Files
leagues-tools/os-league-tools-master/src/store/user/account.js

35 lines
1.0 KiB
JavaScript

/* Redux toolkit middleware handles updates immutably, but eslint doesn't know that */
/* eslint-disable no-param-reassign */
import { createSlice } from '@reduxjs/toolkit';
export const CURRENT_VERSION = 3;
const INITIAL_STATE = {
version: CURRENT_VERSION,
accountCache: {
isLoggedIn: false,
userEmail: undefined,
accessToken: undefined,
},
};
export const accountSlice = createSlice({
name: 'account',
initialState: INITIAL_STATE,
reducers: {
updateAccountCache: (state, action) => {
state.accountCache.isLoggedIn = action.payload.isAuthenticated;
state.accountCache.userEmail = action.payload.isAuthenticated ? action.payload.user.email : undefined;
state.accountCache.accessToken = action.payload.isAuthenticated ? action.payload.accessToken : undefined;
},
reset: () => INITIAL_STATE,
},
});
// Don't cache anything across sessions, let auth0 handle it
export const loadState = () => INITIAL_STATE;
export const { updateAccountCache, reset } = accountSlice.actions;
export default accountSlice.reducer;