Merge branch 'master'
[arvados-workbench2.git] / src / store / auth / auth-reducer.ts
index 57a17ae53cfbb45f9c69529ad34d866771b0f215..366385d50b506de529139f3f75151762f6a6285a 100644 (file)
@@ -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;