File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed
apps/playground/src/store Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { jwtDecode } from 'jwt-decode';
22
33import type { AuthSlice , SliceCreator } from '../types' ;
44
5- export const createAuthSlice : SliceCreator < AuthSlice > = ( set ) => ( {
5+ export const createAuthSlice : SliceCreator < AuthSlice > = ( set , get ) => ( {
66 auth : null ,
77 login : ( accessToken ) => {
88 set ( ( state ) => {
@@ -11,5 +11,13 @@ export const createAuthSlice: SliceCreator<AuthSlice> = (set) => ({
1111 payload : jwtDecode ( accessToken )
1212 } ;
1313 } ) ;
14+ } ,
15+ revalidateToken : ( ) => {
16+ const { auth } = get ( ) ;
17+ if ( auth ?. payload . exp && Date . now ( ) / 1000 > auth . payload . exp ) {
18+ set ( ( state ) => {
19+ state . auth = null ;
20+ } ) ;
21+ }
1422 }
1523} ) ;
Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ export type AuthSlice = {
4141 payload : JwtPayload ;
4242 } ;
4343 login : ( accessToken : string ) => void ;
44+ revalidateToken : ( ) => void ;
4445} ;
4546
4647export type EditorState = {
You can’t perform that action at this time.
0 commit comments