import { createSlice } from "@reduxjs/toolkit";

const initialState = { user: null, token: null }

const authSlice = createSlice({
    name: 'auth',
    initialState,
    reducers: {
      setCredentials: (state, { payload: { user, token } }) => {
        state.user = user
        state.token = token
      },
      setCredentialsInitial: (state) => {
        return initialState
      },
      setNull: () => {
        return { user: null, token: null }
      }

    },
  })

export const { setCredentials, setCredentialsInitial, setNull } = authSlice.actions

export default authSlice.reducer
