X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/28bb06ae7b9983da793f2459c5cc3e8debd71949..bccb9ca5151f041d8c8b73098a3e1874023e3efa:/src/store/auth/auth-reducer.ts diff --git a/src/store/auth/auth-reducer.ts b/src/store/auth/auth-reducer.ts index 57a17ae5..366385d5 100644 --- a/src/store/auth/auth-reducer.ts +++ b/src/store/auth/auth-reducer.ts @@ -2,19 +2,18 @@ // // SPDX-License-Identifier: AGPL-3.0 -import actions, { AuthAction } from "./auth-action"; +import { authActions, AuthAction } from "./auth-action"; import { User } from "../../models/user"; import { authService } from "../../services/services"; import { removeServerApiAuthorizationHeader, setServerApiAuthorizationHeader } from "../../common/api/server-api"; -import { UserDetailsResponse } from "../../services/auth-service/auth-service"; export interface AuthState { user?: User; apiToken?: string; -}; +} -const authReducer = (state: AuthState = {}, action: AuthAction) => { - return actions.match(action, { +export const authReducer = (state: AuthState = {}, action: AuthAction) => { + return authActions.match(action, { SAVE_API_TOKEN: (token: string) => { authService.saveApiToken(token); setServerApiAuthorizationHeader(token); @@ -39,17 +38,10 @@ const authReducer = (state: AuthState = {}, action: AuthAction) => { authService.logout(); return {...state, apiToken: undefined}; }, - USER_DETAILS_SUCCESS: (ud: UserDetailsResponse) => { - const user = { - email: ud.email, - firstName: ud.first_name, - lastName: ud.last_name - }; + USER_DETAILS_SUCCESS: (user: User) => { authService.saveUser(user); return {...state, user}; }, default: () => state }); }; - -export default authReducer;