Skip to content

Commit

Permalink
fix: logging-in should not navigate to auth/logout (#407)
Browse files Browse the repository at this point in the history
* When the logout button is clicked in development mode, the app navigates
  to /auth/logout, which in turn sets up a redirect_uri to the root uri.
  However, redirecting preserves the logout uri as the final target uri
  and ends up displaying a blank page.

* If the current uri is /auth/logout when creating a login then reset it
  back to / ensuring that the blank page is never displayed and the app
  correctly logs in.
  • Loading branch information
phantomjinx committed Apr 22, 2024
1 parent 515a00a commit 1e645cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 6 additions & 1 deletion packages/oauth/src/openshift/osoauth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import $ from 'jquery'
import { OAuthProtoService } from '../api'
import { UserProfile, log } from '../globals'
import { CLUSTER_CONSOLE_KEY } from '../metadata'
import { fetchPath, getCookie, isBlank, redirect } from '../utils'
import { fetchPath, getCookie, isBlank, logoutUri, redirect } from '../utils'
import {
CLUSTER_VERSION_KEY,
DEFAULT_CLUSTER_VERSION,
Expand Down Expand Up @@ -237,6 +237,11 @@ export class OSOAuthService implements OAuthProtoService {
}

const currentURI = new URL(window.location.href)
if (currentURI.pathname === logoutUri().pathname) {
//Reset the logout path to the base path
currentURI.pathname = currentURI.pathname.replace(logoutUri().pathname, '/')
}

try {
this.clearKeepAlive()

Expand Down
10 changes: 7 additions & 3 deletions packages/oauth/src/utils/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ async function logoutRedirectAvailable(): Promise<boolean> {
return true
}

export function logoutUri(): URL {
return new URL(relToAbsUrl(LOGOUT_ENDPOINT))
}

export function logoutRedirect(redirectUri: URL): void {
// Have a logout page so append redirect uri to its url
const logoutUri = new URL(relToAbsUrl(LOGOUT_ENDPOINT))
logoutUri.searchParams.append('redirect_uri', redirectUri.toString())
const targetUri = logoutUri()
targetUri.searchParams.append('redirect_uri', redirectUri.toString())

logoutRedirectAvailable().then(exists => {
if (exists) redirect(logoutUri)
if (exists) redirect(targetUri)
else redirect(redirectUri)
})
}
Expand Down

0 comments on commit 1e645cd

Please sign in to comment.