Skip to content

Commit c2bf8a7

Browse files
committed
frontend: components: redux: Add oidc autologin and config
1 parent 6ff15c2 commit c2bf8a7

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

frontend/src/components/App/Layout.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,29 +248,34 @@ export default function Layout({}: LayoutProps) {
248248
if (!oidcAutoLogin || !clusters) {
249249
return;
250250
}
251-
const urlParams = new URLSearchParams(window.location.search);
251+
const urlParams = new URLSearchParams(location.search);
252252
const isLoggingOut = urlParams.get('logout') === 'true';
253253
if (isLoggingOut || !!error) {
254254
return;
255255
}
256256
const isCallbackPath =
257-
window.location.pathname.includes('oidc-callback') ||
257+
location.pathname.includes('oidc-callback') ||
258258
urlParams.has('code') ||
259259
urlParams.has('state');
260260
if (isCallbackPath) {
261261
return;
262262
}
263263
const currentClusterName = getCluster();
264-
const currentCluster = currentClusterName ? clusters[currentClusterName] : null;
264+
if (!currentClusterName) {
265+
return;
266+
}
267+
const currentCluster = clusters[currentClusterName];
265268
const isOIDC = currentCluster?.auth_type === 'oidc';
266269
if (!isOIDC) {
267270
return;
268271
}
269272
if (currentCluster.useToken === undefined) {
270-
const oauthUrl = `${getAppUrl()}oidc?dt=${Date.now()}&cluster=${getCluster()}`;
273+
const oauthUrl = `${getAppUrl()}oidc?dt=${Date.now()}&cluster=${encodeURIComponent(
274+
currentClusterName
275+
)}`;
271276
window.location.href = oauthUrl;
272277
}
273-
}, [oidcAutoLogin, clusters, error, location.pathname]);
278+
}, [oidcAutoLogin, clusters, error, location.pathname, location.search]);
274279

275280
if (!disableBackendLoader) {
276281
if (error && !config) {

frontend/src/redux/configSlice.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export interface ConfigState {
6060
/**
6161
* Whether OIDC auto-login is enabled. Null indicates the value hasn't been loaded from the backend yet.
6262
*/
63-
oidcAutoLogin?: boolean | null;
63+
oidcAutoLogin: boolean | null;
6464
}
6565

6666
export const defaultTableRowsPerPageOptions = [15, 25, 50];
@@ -100,7 +100,7 @@ const configSlice = createSlice({
100100
) {
101101
state.clusters = action.payload.clusters;
102102

103-
if (state.oidcAutoLogin !== undefined) {
103+
if (action.payload.oidcAutoLogin !== undefined) {
104104
state.oidcAutoLogin = action.payload.oidcAutoLogin;
105105
}
106106
},

0 commit comments

Comments
 (0)