Skip to content

Redirect loop fix #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions pkg/errors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import { NextRouter } from "next/router"
import { Dispatch, SetStateAction } from "react"
import { toast } from "react-toastify"

function handleAal2Error(jsonResponse: any, router: NextRouter,) {
if (jsonResponse.error?.id === "session_aal2_required") {
window.location.href = "/auth/login?aal=aal2"
}
else {
router.push("/welcome")
}
}

// A small function to help us deal with errors coming from fetching a flow.
export function handleGetFlowError<S>(
router: NextRouter,
Expand All @@ -16,8 +25,10 @@ export function handleGetFlowError<S>(
window.location.href = (err.response?.data as any).redirect_browser_to
return
case "session_already_available":
// User is already signed in, let's redirect them home!
await router.push("/welcome")
await fetch('/.ory/kratos/public/sessions/whoami')
.then(response => response.json())
.then((jsonResponse) => handleAal2Error(jsonResponse, router))
.catch(() => { router.push("/welcome") });
return
case "session_refresh_required":
// We need to re-authenticate to perform this action
Expand Down