blob: e1fec78b4b0e4c9c9bab9d50d26687d2f4990a39 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import { createSlice } from '@reduxjs/toolkit';
import type { PayloadAction } from '@reduxjs/toolkit';
import type { RootState } from '../store';
import type { Guest } from './apiSlice';
type AuthState = {
guest?: Guest;
token?: string;
};
const authSlice = createSlice({
name: 'auth',
initialState: { guest: undefined, token: undefined } as AuthState,
reducers: {
setCredentials: (
state,
{
payload: { guest, token },
}: PayloadAction<{ guest: Guest; token: string }>
) => {
state.guest = guest;
state.token = token;
},
},
});
export const { setCredentials } = authSlice.actions;
export default authSlice.reducer;
export const selectCurrentGuest = (state: RootState) => state.auth.guest;
|