X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/aed25c0fef7e65b307d702e8ee515567d6c2a7c1..e8e0182d65a74b1a222127eb8b36f31a906b14c8:/src/store/auth/auth-reducer.ts?ds=sidebyside diff --git a/src/store/auth/auth-reducer.ts b/src/store/auth/auth-reducer.ts index 8f234dad..a8e4340a 100644 --- a/src/store/auth/auth-reducer.ts +++ b/src/store/auth/auth-reducer.ts @@ -10,7 +10,7 @@ import { SshKeyResource } from '~/models/ssh-key'; export interface AuthState { user?: User; apiToken?: string; - sshKeys?: SshKeyResource[]; + sshKeys: SshKeyResource[]; } const initialState: AuthState = { @@ -19,13 +19,13 @@ const initialState: AuthState = { sshKeys: [] }; -export const authReducer = (services: ServiceRepository) => (state: AuthState = initialState, action: AuthAction) => { +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; @@ -40,7 +40,10 @@ export const authReducer = (services: ServiceRepository) => (state: AuthState = return {...state, sshKeys}; }, ADD_SSH_KEY: (sshKey: SshKeyResource) => { - return { ...state, sshKeys: state.sshKeys!.concat(sshKey) }; + return { ...state, sshKeys: state.sshKeys.concat(sshKey) }; + }, + REMOVE_SSH_KEY: (uuid: string) => { + return { ...state, sshKeys: state.sshKeys.filter((sshKey) => sshKey.uuid !== uuid )}; }, default: () => state });