import { createSlice , PayloadAction } from '@reduxjs/toolkit' ; import { RootState } from '../../app/store' ; interface AuthorizationState { loggedIn : boolean ; accessToken : string ; tokenExpiryDate : string ; } const initialState = { loggedIn : false , accessToken : '' , tokenExpiryDate : '' , } ; export const authorizationSlice = createSlice ( { name : 'authorization' , initialState , reducers : { setLoggedIn : ( state , action ) => { state . loggedIn = action . payload ; } , setAccessToken : ( state , action ) => { state . accessToken = action . payload ; } , setTokenExpiryDate : ( state , action ) => { const date = new Date ( ) ; date . setSeconds ( date . getSeconds ( ) + action . payload ) ; state . tokenExpiryDate = date . toISOString ( ) ; } , } , } ) ; export const { setLoggedIn , setAccessToken , setTokenExpiryDate } = authorizationSlice . actions ; export const selectIsLoggedIn = ( state ) => state . authorization . loggedIn ; export const selectAccessToken = ( state ) => state . authorization . accessToken ; export const selectTokenExpiryDate = ( state ) => state . authorization . tokenExpiryDate ; export default authorizationSlice . reducer ;