1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { authActions, AuthAction } from "./auth-action";
6 import { User } from "~/models/user";
7 import { ServiceRepository } from "~/services/services";
9 export interface AuthState {
14 export const authReducer = (services: ServiceRepository) => (state: AuthState = {}, action: AuthAction) => {
15 return authActions.match(action, {
16 SAVE_API_TOKEN: (token: string) => {
17 return {...state, apiToken: token};
19 INIT: ({ user, token }) => {
20 return { user, apiToken: token };
26 return {...state, apiToken: undefined};
28 USER_DETAILS_SUCCESS: (user: User) => {
29 return {...state, user};