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";
8 import { SshKeyResource } from '~/models/ssh-key';
10 export interface AuthState {
13 sshKeys?: SshKeyResource[];
16 const initialState: AuthState = {
22 export const authReducer = (services: ServiceRepository) => (state: AuthState = initialState, action: AuthAction) => {
23 return authActions.match(action, {
24 SAVE_API_TOKEN: (token: string) => {
25 return {...state, apiToken: token};
27 INIT: ({ user, token }) => {
28 return { user, apiToken: token };
34 return {...state, apiToken: undefined};
36 USER_DETAILS_SUCCESS: (user: User) => {
37 return {...state, user};
39 SET_SSH_KEYS: (sshKeys: SshKeyResource[]) => {
40 return {...state, sshKeys};
42 ADD_SSH_KEY: (sshKey: SshKeyResource) => {
43 return { ...state, sshKeys: state.sshKeys!.concat(sshKey) };