// SPDX-License-Identifier: AGPL-3.0
import { authActions, AuthAction } from "./auth-action";
-import { User } from "~/models/user";
+import { User, UserResource } from "~/models/user";
import { ServiceRepository } from "~/services/services";
import { SshKeyResource } from '~/models/ssh-key';
import { Session } from "~/models/session";
+import { Config } from '~/common/config';
export interface AuthState {
user?: User;
localCluster: string;
homeCluster: string;
remoteHosts: { [key: string]: string };
+ remoteHostsConfig: { [key: string]: Config };
}
const initialState: AuthState = {
sessions: [],
localCluster: "",
homeCluster: "",
- remoteHosts: {}
+ remoteHosts: {},
+ remoteHostsConfig: {}
};
export const authReducer = (services: ServiceRepository) => (state = initialState, action: AuthAction) => {
SAVE_API_TOKEN: (token: string) => {
return { ...state, apiToken: token };
},
- CONFIG: ({ uuidPrefix, remoteHosts }) => {
+ SAVE_USER: (user: UserResource) => {
+ return { ...state, user};
+ },
+ CONFIG: ({ config }) => {
+ return {
+ ...state,
+ localCluster: config.uuidPrefix,
+ remoteHosts: { ...config.remoteHosts, [config.uuidPrefix]: new URL(config.rootUrl).host },
+ homeCluster: config.uuidPrefix
+ };
+ },
+ REMOTE_CLUSTER_CONFIG: ({ config }) => {
return {
- ...state, localCluster: uuidPrefix, remoteHosts, homeCluster: uuidPrefix
+ ...state,
+ remoteHostsConfig: { ...state.remoteHostsConfig, [config.uuidPrefix]: config },
};
},
INIT: ({ user, token }) => {