Skip to content

Commit

Permalink
fix: (OAuth) redirect to direct login on failure (#3406)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmintey authored Apr 2, 2024
1 parent 2a3463b commit f709d11
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions frontend/schemes/DynamicOpenIDConnectScheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export default class DynamicOpenIDConnectScheme extends OpenIDConnectScheme {
}

async _handleCallback() {
// sometimes the mealie token is being sent in the request to the IdP on callback which
// causes an error, so we clear it if we have one
if (this.token.get()) {
this.token.reset();
}
const redirect = await super._handleCallback()
await this.updateAccessToken()

Expand All @@ -49,13 +54,20 @@ export default class DynamicOpenIDConnectScheme extends OpenIDConnectScheme {
return
}

const response = await this.$auth.requestWith(this.name, {
url: "/api/auth/token",
method: "post"
})

// Update tokens with mealie token
this.updateTokens(response)
try {
const response = await this.$auth.requestWith(this.name, {
url: "/api/auth/token",
method: "post"
})
// Update tokens with mealie token
this.updateTokens(response)
} catch {
const currentUrl = new URL(window.location.href)
if (currentUrl.pathname === "/login" && currentUrl.searchParams.has("direct")) {
return
}
window.location.replace("/login?direct=1")
}
}

isValidMealieToken() {
Expand Down

0 comments on commit f709d11

Please sign in to comment.