Merge pull request #11 from kylecorbelli/improve-signoutuser
Improve signOutUser
This commit is contained in:
commit
c078f46628
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "redux-token-auth",
|
||||
"version": "0.11.0",
|
||||
"version": "0.12.0",
|
||||
"description": "Redux actions and reducers to integrate with Devise Token Auth",
|
||||
"main": "dist/index.js",
|
||||
"types": "index.d.ts",
|
||||
|
|
|
@ -212,9 +212,12 @@ const generateAuthActions = (config: { [key: string]: any }): ActionsExport => {
|
|||
}
|
||||
}
|
||||
|
||||
const signOutUser = (
|
||||
userSignOutCredentials: UserSignOutCredentials,
|
||||
) => async function (dispatch: Dispatch<{}>): Promise<void> {
|
||||
const signOutUser = () => async function (dispatch: Dispatch<{}>): Promise<void> {
|
||||
const userSignOutCredentials: UserSignOutCredentials = {
|
||||
'access-token': localStorage.getItem('access-token') as string,
|
||||
client: localStorage.getItem('client') as string,
|
||||
uid: localStorage.getItem('uid') as string,
|
||||
}
|
||||
dispatch(signOutRequestSent())
|
||||
try {
|
||||
await axios({
|
||||
|
|
|
@ -42,6 +42,7 @@ describe('currentUser', () => {
|
|||
const loggedInUser: User = {
|
||||
attributes: {
|
||||
firstName: 'Snowball',
|
||||
imageUrl: 'http://some.url',
|
||||
},
|
||||
isLoading: false,
|
||||
isLoggedIn: true,
|
||||
|
@ -169,6 +170,7 @@ describe('currentUser', () => {
|
|||
const expectedNewState: User = {
|
||||
attributes: {
|
||||
firstName: null,
|
||||
imageUrl: null,
|
||||
},
|
||||
isLoading: false,
|
||||
isLoggedIn: false,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import {
|
||||
User,
|
||||
UserAttributes,
|
||||
ReduxAction,
|
||||
REGISTRATION_REQUEST_SENT,
|
||||
REGISTRATION_REQUEST_SUCCEEDED,
|
||||
|
@ -49,12 +50,19 @@ const currentUser = (state: User = initialUser, action: ReduxAction): User => {
|
|||
isLoggedIn: false,
|
||||
}
|
||||
case SIGNOUT_REQUEST_SUCCEEDED:
|
||||
const userAttributeKeys: string[] = Object.keys(state.attributes)
|
||||
const allNullUserAttributes: UserAttributes = userAttributeKeys.reduce(
|
||||
(accumulatedNullUserAttributes: UserAttributes, currentUserAttributeKey: string): UserAttributes => {
|
||||
return {
|
||||
...accumulatedNullUserAttributes,
|
||||
[currentUserAttributeKey]: null,
|
||||
}
|
||||
},
|
||||
{},
|
||||
)
|
||||
return {
|
||||
...state,
|
||||
attributes: {
|
||||
...state.attributes,
|
||||
firstName: null,
|
||||
},
|
||||
attributes: allNullUserAttributes,
|
||||
isLoading: false,
|
||||
isLoggedIn: false,
|
||||
}
|
||||
|
|
|
@ -3,7 +3,9 @@ import {
|
|||
Store,
|
||||
} from 'redux'
|
||||
|
||||
export interface UserAttributes {}
|
||||
export interface UserAttributes {
|
||||
[key: string]: string | number | null
|
||||
}
|
||||
|
||||
export interface User {
|
||||
readonly isLoggedIn: boolean
|
||||
|
|
Loading…
Reference in New Issue
Block a user