From 086bc71dd6f592eca9a642ac83ba22481d0f70e7 Mon Sep 17 00:00:00 2001 From: "henry.liu" Date: Fri, 22 Nov 2024 16:15:29 +0800 Subject: [PATCH] fix(ui): fix login redirect failed when basehref is set Signed-off-by: henry.liu --- ui/src/app/app.tsx | 4 ++-- ui/src/app/login/components/login.tsx | 4 +++- ui/src/app/utils.ts | 5 +++++ 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 ui/src/app/utils.ts diff --git a/ui/src/app/app.tsx b/ui/src/app/app.tsx index 2d2e192590fa2d..4d5860b4b10071 100644 --- a/ui/src/app/app.tsx +++ b/ui/src/app/app.tsx @@ -22,10 +22,10 @@ import {AuthSettings} from './shared/models'; import {PKCEVerification} from './login/components/pkce-verify'; import {getPKCERedirectURI, pkceLogin} from './login/components/utils'; import {SystemLevelExtension} from './shared/services/extensions-service'; +import {getBase} from './utils'; services.viewPreferences.init(); -const bases = document.getElementsByTagName('base'); -const base = bases.length > 0 ? bases[0].getAttribute('href') || '/' : '/'; +const base = getBase(); export const history = createBrowserHistory({basename: base}); requests.setBaseHRef(base); diff --git a/ui/src/app/login/components/login.tsx b/ui/src/app/login/components/login.tsx index 0f1aa90f260522..5ed9df2dc22898 100644 --- a/ui/src/app/login/components/login.tsx +++ b/ui/src/app/login/components/login.tsx @@ -8,6 +8,7 @@ import {AppContext} from '../../shared/context'; import {AuthSettings} from '../../shared/models'; import {services} from '../../shared/services'; import {getPKCERedirectURI, pkceLogin} from './utils'; +import {getBase} from '../../utils'; require('./login.scss'); @@ -135,7 +136,8 @@ export class Login extends React.Component, State> { this.setState({loginInProgress: false}); if (returnURL) { const url = new URL(returnURL); - this.appContext.apis.navigation.goto(url.pathname + url.search); + const base = getBase(); + this.appContext.apis.navigation.goto(url.pathname.slice(base.length - 1) + url.search); } else { this.appContext.apis.navigation.goto('/applications'); } diff --git a/ui/src/app/utils.ts b/ui/src/app/utils.ts new file mode 100644 index 00000000000000..7504af90e52aac --- /dev/null +++ b/ui/src/app/utils.ts @@ -0,0 +1,5 @@ +export const getBase = () => { + const bases = document.getElementsByTagName('base'); + + return bases.length > 0 ? bases[0].getAttribute('href') || '/' : '/'; +};