mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-14 00:32:35 +10:00
🚀 release v3.0.0
This commit is contained in:
33
client/store/auth/authSlice.ts
Normal file
33
client/store/auth/authSlice.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { User } from '@reactive-resume/schema';
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||||
|
||||
type AuthState = {
|
||||
user: User | null;
|
||||
accessToken: string | null;
|
||||
isLoggedIn: boolean;
|
||||
};
|
||||
|
||||
const initialState: AuthState = {
|
||||
user: null,
|
||||
accessToken: null,
|
||||
isLoggedIn: false,
|
||||
};
|
||||
|
||||
export const authSlice = createSlice({
|
||||
name: 'auth',
|
||||
initialState,
|
||||
reducers: {
|
||||
setUser: (state, action: PayloadAction<User>) => {
|
||||
state.user = action.payload;
|
||||
},
|
||||
setAccessToken: (state, action: PayloadAction<string>) => {
|
||||
state.accessToken = action.payload;
|
||||
state.isLoggedIn = true;
|
||||
},
|
||||
logout: () => initialState,
|
||||
},
|
||||
});
|
||||
|
||||
export const { setUser, setAccessToken, logout } = authSlice.actions;
|
||||
|
||||
export default authSlice.reducer;
|
||||
Reference in New Issue
Block a user