UNPKG

react-auth-verification-context

Version:

react-auth-verification-context is a library that provides a way to manage authentication state in a React application. It is implemented using the React context API, which allows you to pass data through the component tree without having to pass props do

24 lines (23 loc) 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.authReducer = exports.AuthActions = void 0; var AuthActions; (function (AuthActions) { AuthActions["RestoreToken"] = "RESTORE_TOKEN"; AuthActions["SignIn"] = "SIGN_IN"; AuthActions["SignOut"] = "SIGN_OUT"; AuthActions["Loading"] = "LOADING"; })(AuthActions = exports.AuthActions || (exports.AuthActions = {})); const authReducer = (state, action) => { switch (action.type) { case AuthActions.RestoreToken: return Object.assign(Object.assign({}, state), { isLoading: false, attributes: action.payload, isAuthenticated: action.payload ? true : false }); case AuthActions.SignIn: return Object.assign(Object.assign({}, state), { attributes: action.payload, isAuthenticated: action.payload ? true : false }); case AuthActions.SignOut: return Object.assign(Object.assign({}, state), { isLoading: false, attributes: null, isAuthenticated: false }); default: return state; } }; exports.authReducer = authReducer;