sigit.io/src/store/auth/reducer.ts

56 lines
1.0 KiB
TypeScript
Raw Normal View History

import * as ActionTypes from '../actionTypes'
import { AuthDispatchTypes, AuthState } from './types'
const initialState: AuthState = {
loggedIn: false
}
const reducer = (
state = initialState,
action: AuthDispatchTypes
): AuthState | null => {
switch (action.type) {
case ActionTypes.SET_AUTH_STATE: {
const { loginMethod, keyPair, nsecBunkerPubkey } = state
return {
loginMethod,
keyPair,
nsecBunkerPubkey,
...action.payload
}
}
case ActionTypes.UPDATE_LOGIN_METHOD: {
const { payload } = action
return {
...state,
loginMethod: payload
}
}
case ActionTypes.UPDATE_KEYPAIR: {
const { payload } = action
return {
...state,
keyPair: payload
}
}
case ActionTypes.UPDATE_NSECBUNKER_PUBKEY: {
const { payload } = action
return {
...state,
nsecBunkerPubkey: payload
}
}
default:
return state
}
}
export default reducer