Implement authentication features with login, registration, and user management; update service configurations for development and production environments.
This commit is contained in:
@@ -2,14 +2,15 @@
|
||||
/* eslint-disable no-param-reassign */
|
||||
import { createSlice } from '@reduxjs/toolkit';
|
||||
|
||||
export const CURRENT_VERSION = 3;
|
||||
export const CURRENT_VERSION = 4;
|
||||
|
||||
const INITIAL_STATE = {
|
||||
version: CURRENT_VERSION,
|
||||
accountCache: {
|
||||
isLoggedIn: false,
|
||||
isChecking: true,
|
||||
username: undefined,
|
||||
userEmail: undefined,
|
||||
accessToken: undefined,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -17,18 +18,28 @@ 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;
|
||||
setAuthChecking: (state, action) => {
|
||||
state.accountCache.isChecking = action.payload;
|
||||
},
|
||||
setLoggedIn: (state, action) => {
|
||||
state.accountCache.isLoggedIn = true;
|
||||
state.accountCache.isChecking = false;
|
||||
state.accountCache.username = action.payload.username;
|
||||
state.accountCache.userEmail = action.payload.email;
|
||||
},
|
||||
setLoggedOut: state => {
|
||||
state.accountCache.isLoggedIn = false;
|
||||
state.accountCache.isChecking = false;
|
||||
state.accountCache.username = undefined;
|
||||
state.accountCache.userEmail = undefined;
|
||||
},
|
||||
reset: () => INITIAL_STATE,
|
||||
},
|
||||
});
|
||||
|
||||
// Don't cache anything across sessions, let auth0 handle it
|
||||
// Don't cache anything across sessions, session cookie handles it
|
||||
export const loadState = () => INITIAL_STATE;
|
||||
|
||||
export const { updateAccountCache, reset } = accountSlice.actions;
|
||||
export const { setAuthChecking, setLoggedIn, setLoggedOut, reset } = accountSlice.actions;
|
||||
|
||||
export default accountSlice.reducer;
|
||||
|
||||
Reference in New Issue
Block a user