Skip to content

Commit c05f40f

Browse files
gustavosbarretoluannmoreira
authored andcommitted
feat(api): add configuration management to BaseAPI
- Introduced `getConfiguration` and `setConfiguration` methods to `BaseAPI`. - Added a `reloadConfiguration` function to reapply settings across APIs. - Updated the auth module to integrate configuration updates on login. - Enhanced `apiPlugin` to reload configuration after authentication success. - Redirected users to the home page post-login in `Login.vue`.
1 parent 3be0fa7 commit c05f40f

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

ui/src/api/http.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ export const createNewClient = () => Function;
100100
declare module "./client/base" {
101101
interface BaseAPI {
102102
getAxios(): AxiosInstance;
103+
getConfiguration(): Configuration | undefined;
104+
setConfiguration(configuration: Configuration): void;
103105
}
104106
}
105107

@@ -108,8 +110,39 @@ BaseAPI.prototype.getAxios = function getAxios(this: BaseAPI): AxiosInstance {
108110
return this.axios;
109111
};
110112

113+
/** Returns the configuration */
114+
BaseAPI.prototype.getConfiguration = function getConfiguration(this: BaseAPI): Configuration | undefined {
115+
return this.configuration;
116+
};
117+
118+
/** Sets the configuration */
119+
BaseAPI.prototype.setConfiguration = function setConfiguration(this: BaseAPI, configuration: Configuration): void {
120+
this.configuration = configuration;
121+
};
122+
123+
// Reloads the configuration for all APIs
124+
const reloadConfiguration = () => {
125+
[
126+
sessionsApi,
127+
devicesApi,
128+
containersApi,
129+
systemApi,
130+
namespacesApi,
131+
apiKeysApi,
132+
sshApi,
133+
tagsApi,
134+
usersApi,
135+
mfaApi,
136+
billingApi,
137+
rulesApi,
138+
].forEach((api) => {
139+
api.setConfiguration(configuration);
140+
});
141+
};
142+
111143
export {
112144
configuration,
145+
reloadConfiguration,
113146
sessionsApi,
114147
devicesApi,
115148
containersApi,

ui/src/store/modules/auth.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import * as apiAuth from "../api/auth";
55
import * as apiNamespace from "../api/namespaces";
66
import { IUserLogin } from "@/interfaces/IUserLogin";
77
import { State } from "..";
8+
import {
9+
configuration as apiConfiguration,
10+
reloadConfiguration as reloadApiConfiguration,
11+
} from "@/api/http";
812

913
const { reset, toggle } = useChatWoot();
1014
export interface AuthState {
@@ -211,7 +215,8 @@ export const auth: Module<AuthState, State> = {
211215
async loginToken(context, token) {
212216
context.commit("authRequest");
213217

214-
localStorage.setItem("token", token);
218+
apiConfiguration.accessToken = token;
219+
reloadApiConfiguration();
215220

216221
try {
217222
const resp = await apiAuth.info();

ui/src/store/plugins/api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { configuration } from "@/api/http";
1+
import { configuration, reloadConfiguration } from "@/api/http";
22

33
const apiPlugin = (store) => {
44
store.subscribe((mutation, state) => {
55
if (mutation.type === "auth/authSuccess") {
66
configuration.accessToken = state.auth.token;
7+
reloadConfiguration();
78
}
89
});
910
};

ui/src/views/Login.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ onMounted(async () => {
193193
await store.dispatch("namespaces/clearNamespaceList");
194194
await store.dispatch("auth/logout");
195195
await store.dispatch("auth/loginToken", route.query.token);
196+
197+
window.location.href = "/";
196198
});
197199
198200
const login = async () => {

0 commit comments

Comments
 (0)