remove SshKey interface and change object type
[arvados-workbench2.git] / src / store / auth / auth-reducer.ts
index 1546212b08fe846834bb84d61cf098dedf2c40c3..8f234dad35bf8a9d68f508ab47d4a1166eea454e 100644 (file)
@@ -3,15 +3,23 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { authActions, AuthAction } from "./auth-action";
-import { User } from "../../models/user";
-import { ServiceRepository } from "../../services/services";
+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: AuthState = initialState, action: AuthAction) => {
     return authActions.match(action, {
         SAVE_API_TOKEN: (token: string) => {
             return {...state, apiToken: token};
@@ -28,6 +36,12 @@ 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) };
+        },
         default: () => state
     });
 };