Skip to content
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