X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/24ddc06cb04b124d337e91c190230bfad83e490b..785a62a8934dc439cbd201d9011775ccbcbb2c24:/src/store/auth/auth-reducer.ts diff --git a/src/store/auth/auth-reducer.ts b/src/store/auth/auth-reducer.ts index ac9ecbe5..a8e4340a 100644 --- a/src/store/auth/auth-reducer.ts +++ b/src/store/auth/auth-reducer.ts @@ -3,22 +3,29 @@ // SPDX-License-Identifier: AGPL-3.0 import { authActions, AuthAction } from "./auth-action"; -import { User } from "../../models/user"; -import { ServiceRepository } from "../../services/services"; -import { removeServerApiAuthorizationHeader, setServerApiAuthorizationHeader } from "../../common/api/server-api"; +import { User } from "~/models/user"; +import { ServiceRepository } from "~/services/services"; +import { SshKeyResource } from '~/models/ssh-key'; export interface AuthState { user?: User; apiToken?: string; + sshKeys: SshKeyResource[]; } -export const authReducer = (services: ServiceRepository) => (state: AuthState = {}, action: AuthAction) => { +const initialState: AuthState = { + user: undefined, + apiToken: undefined, + sshKeys: [] +}; + +export const authReducer = (services: ServiceRepository) => (state = initialState, action: AuthAction) => { return authActions.match(action, { SAVE_API_TOKEN: (token: string) => { return {...state, apiToken: token}; }, INIT: ({ user, token }) => { - return { user, apiToken: token }; + return { ...state, user, apiToken: token }; }, LOGIN: () => { return state; @@ -29,6 +36,15 @@ export const authReducer = (services: ServiceRepository) => (state: AuthState = USER_DETAILS_SUCCESS: (user: User) => { return {...state, user}; }, + SET_SSH_KEYS: (sshKeys: SshKeyResource[]) => { + return {...state, sshKeys}; + }, + ADD_SSH_KEY: (sshKey: SshKeyResource) => { + return { ...state, sshKeys: state.sshKeys.concat(sshKey) }; + }, + REMOVE_SSH_KEY: (uuid: string) => { + return { ...state, sshKeys: state.sshKeys.filter((sshKey) => sshKey.uuid !== uuid )}; + }, default: () => state }); };