X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/5320327aa99710bb1cd1ce090fcb8e2b1d6de0da..1a9eb2261e6030ba78078e2a206bad27653f2475:/src/store/auth/auth-reducer.ts diff --git a/src/store/auth/auth-reducer.ts b/src/store/auth/auth-reducer.ts index c5a485648f..f6974fd207 100644 --- a/src/store/auth/auth-reducer.ts +++ b/src/store/auth/auth-reducer.ts @@ -2,15 +2,15 @@ // // SPDX-License-Identifier: AGPL-3.0 -import actions, { AuthAction, UserDetailsResponse } from "./auth-action"; +import actions, { AuthAction } from "./auth-action"; import { User } from "../../models/user"; import { authService } from "../../services/services"; -import { removeServerApiAuthorizationHeader, setServerApiAuthorizationHeader } from "../../common/server-api"; +import { removeServerApiAuthorizationHeader, setServerApiAuthorizationHeader } from "../../common/api/server-api"; export interface AuthState { user?: User; apiToken?: string; -}; +} const authReducer = (state: AuthState = {}, action: AuthAction) => { return actions.match(action, { @@ -22,6 +22,9 @@ const authReducer = (state: AuthState = {}, action: AuthAction) => { INIT: () => { const user = authService.getUser(); const token = authService.getApiToken(); + if (token) { + setServerApiAuthorizationHeader(token); + } return {user, apiToken: token}; }, LOGIN: () => { @@ -35,12 +38,7 @@ 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}; },