mirror of
https://github.com/henrygd/beszel.git
synced 2026-08-13 05:47:47 +02:00
Fixes redirect-based OAuth login when OAUTH_DISABLE_POPUP=true is set (#2171)
Switch to localStorage, which is shared across all tabs/windows of the same origin. Also clean up the stored entry and strip the callback URL on both success and failure paths.
This commit is contained in:
committed by
GitHub
parent
bd52134558
commit
1aa9fcd31d
@@ -175,8 +175,8 @@ export function UserAuthForm({
|
|||||||
*/
|
*/
|
||||||
function redirectToOauthProvider(provider: AuthProviderInfo) {
|
function redirectToOauthProvider(provider: AuthProviderInfo) {
|
||||||
const url = new URL(provider.authURL)
|
const url = new URL(provider.authURL)
|
||||||
// url.searchParams.set("redirect_uri", `${window.location.origin}${basePath}`)
|
url.searchParams.set("redirect_uri", `${window.location.origin}${basePath}`)
|
||||||
sessionStorage.setItem("provider", JSON.stringify(provider))
|
localStorage.setItem("provider", JSON.stringify(provider))
|
||||||
window.location.href = url.toString()
|
window.location.href = url.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,12 +186,13 @@ export function UserAuthForm({
|
|||||||
const code = params.get("code")
|
const code = params.get("code")
|
||||||
if (code) {
|
if (code) {
|
||||||
const state = params.get("state")
|
const state = params.get("state")
|
||||||
const provider: AuthProviderInfo = JSON.parse(sessionStorage.getItem("provider") ?? "{}")
|
const provider: AuthProviderInfo = JSON.parse(localStorage.getItem("provider") ?? "{}")
|
||||||
|
localStorage.removeItem("provider")
|
||||||
|
window.history.replaceState({}, "", window.location.pathname)
|
||||||
if (!state || provider.state !== state) {
|
if (!state || provider.state !== state) {
|
||||||
showLoginFaliedToast()
|
showLoginFaliedToast()
|
||||||
} else {
|
} else {
|
||||||
setIsOauthLoading(true)
|
setIsOauthLoading(true)
|
||||||
window.history.replaceState({}, "", window.location.pathname)
|
|
||||||
pb.collection("users")
|
pb.collection("users")
|
||||||
.authWithOAuth2Code(provider.name, code, provider.codeVerifier, `${window.location.origin}${basePath}`)
|
.authWithOAuth2Code(provider.name, code, provider.codeVerifier, `${window.location.origin}${basePath}`)
|
||||||
.then(() => $authenticated.set(pb.authStore.isValid))
|
.then(() => $authenticated.set(pb.authStore.isValid))
|
||||||
|
|||||||
Reference in New Issue
Block a user