Skip to content

Commit

Permalink
Fix issue setting nextUrl on click of logout button
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Jul 16, 2024
1 parent 293490d commit 903581f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
11 changes: 7 additions & 4 deletions public/apps/account/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export async function logout(http: HttpStart, logoutUrl?: string): Promise<void>
setShouldShowTenantPopup(null);
// Clear everything in the sessionStorage since they can contain sensitive information
sessionStorage.clear();
// When no basepath is set, we can take '/' as the basepath.
const basePath = http.basePath.serverBasePath ? http.basePath.serverBasePath : '/';
const nextUrl = encodeURIComponent(basePath);
const nextUrl = encodeURIComponent(
window.location.pathname + window.location.search + window.location.hash
);
window.location.href =
logoutUrl || `${http.basePath.serverBasePath}/app/login?nextUrl=${nextUrl}`;
}
Expand All @@ -54,7 +54,10 @@ export async function externalLogout(http: HttpStart, logoutEndpoint: string): P
// This will ensure tenancy is picked up from local storage in the next login.
setShouldShowTenantPopup(null);
sessionStorage.clear();
window.location.href = `${http.basePath.serverBasePath}${logoutEndpoint}`;
const nextUrl = encodeURIComponent(
window.location.pathname + window.location.search + window.location.hash
);
window.location.href = `${http.basePath.serverBasePath}${logoutEndpoint}?nextUrl=${nextUrl}`;
}

export async function updateNewPassword(
Expand Down
7 changes: 6 additions & 1 deletion server/auth/types/openid/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,12 @@ export class OpenIdAuthRoutes {
const token = tokenFromExtraStorage.length
? tokenFromExtraStorage.split(' ')[1]
: cookie?.credentials.authHeaderValue.split(' ')[1]; // get auth token
const nextUrl = getBaseRedirectUrl(this.config, this.core, request);
let nextUrl = getBaseRedirectUrl(this.config, this.core, request);
if (request.url.searchParams.has('nextUrl')) {
nextUrl = `${nextUrl}/app/login?nextUrl=${encodeURIComponent(
request.url.searchParams.get('nextUrl') || ''
)}`;
}

const logoutQueryParams = {
post_logout_redirect_uri: `${nextUrl}`,
Expand Down

0 comments on commit 903581f

Please sign in to comment.