summaryrefslogtreecommitdiff
path: root/client/src/slices/auth/guestSlice.ts
blob: fb4afaf2dc9d81f7a733f63491309a83e686bbc1 (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
import { createSlice } from '@reduxjs/toolkit';
import type { PayloadAction } from '@reduxjs/toolkit';
import type { RootState } from '../../store';
import type { Guest } from '../../models';

type GuestAuth = {
  guest?: Guest;
  token?: string;
};

const guestSlice = createSlice({
  name: 'guest',
  initialState: { guest: undefined, token: undefined } as GuestAuth,
  reducers: {
    setGuest: (
      state,
      { payload: { guest, token } }: PayloadAction<GuestAuth>
    ) => {
      state.guest = guest;
      state.token = token;
    },
  },
});

export const { setGuest } = guestSlice.actions;

export default guestSlice.reducer;

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