2024-02-28 21:49:44 +05:00
|
|
|
import * as ActionTypes from '../actionTypes'
|
|
|
|
import { AuthDispatchTypes, AuthState } from './types'
|
|
|
|
|
|
|
|
const initialState: AuthState = {
|
|
|
|
loggedIn: false
|
|
|
|
}
|
|
|
|
|
|
|
|
const reducer = (
|
|
|
|
state = initialState,
|
|
|
|
action: AuthDispatchTypes
|
2024-10-08 18:42:34 +02:00
|
|
|
): AuthState => {
|
2024-02-28 21:49:44 +05:00
|
|
|
switch (action.type) {
|
|
|
|
case ActionTypes.SET_AUTH_STATE: {
|
2024-10-05 14:56:34 +02:00
|
|
|
const { loginMethod, nostrLoginAuthMethod, keyPair } = state
|
2024-02-28 21:49:44 +05:00
|
|
|
|
|
|
|
return {
|
|
|
|
loginMethod,
|
2024-10-05 14:56:34 +02:00
|
|
|
nostrLoginAuthMethod,
|
2024-02-28 21:49:44 +05:00
|
|
|
keyPair,
|
|
|
|
...action.payload
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case ActionTypes.UPDATE_LOGIN_METHOD: {
|
|
|
|
const { payload } = action
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
loginMethod: payload
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-04 11:37:20 +02:00
|
|
|
case ActionTypes.UPDATE_NOSTR_LOGIN_AUTH_METHOD: {
|
|
|
|
const { payload } = action
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
nostrLoginAuthMethod: payload
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:49:44 +05:00
|
|
|
case ActionTypes.UPDATE_KEYPAIR: {
|
|
|
|
const { payload } = action
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
keyPair: payload
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-08 17:45:51 +05:00
|
|
|
case ActionTypes.RESTORE_STATE:
|
2024-10-08 18:42:34 +02:00
|
|
|
return action.payload.auth || initialState
|
2024-04-08 17:45:51 +05:00
|
|
|
|
2024-02-28 21:49:44 +05:00
|
|
|
default:
|
|
|
|
return state
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default reducer
|