diff options
Diffstat (limited to 'src/features/auth/authSlice.ts')
-rw-r--r-- | src/features/auth/authSlice.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/features/auth/authSlice.ts b/src/features/auth/authSlice.ts new file mode 100644 index 0000000..9716131 --- /dev/null +++ b/src/features/auth/authSlice.ts @@ -0,0 +1,25 @@ +import { createSlice } from '@reduxjs/toolkit'; +import type { RootState } from '../../store'; + +type AuthState = { + user: User | null + token: string | null +} + +const authSlice = createSlice({ + name: 'auth', + initialState: { user: null, token: null } as AuthState, + reducers: { + setCredentials: (state, action) => { + const { user, token } = action.payload; + state.user = user; + state.token = token; + } + } +}); + +export const { setCredentials } = authSlice.actions; + +export default authSlice.reducer; + +export const selectCurrentUser = (state: RootState) => state.auth.user; |