summaryrefslogtreecommitdiff
path: root/client/src/features/auth/authSlice.ts
blob: bff2bdd6c0568eca58b5b204dcc7e81cf8f268ec (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
import { createSlice } 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, action) => {
      const { guest, token } = action.payload;
      state.guest = guest;
      state.token = token;
    },
  },
});

export const { setCredentials } = authSlice.actions;

export default authSlice.reducer;

export const selectCurrentGuest = (state: RootState) => state.auth.guest;