Skip to content
Closed
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions pkg/errors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ 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("/cognition")

}


// A small function to help us deal with errors coming from fetching a flow.
export function handleGetFlowError<S>(
router: NextRouter,
Expand All @@ -16,6 +26,10 @@ export function handleGetFlowError<S>(
window.location.href = (err.response?.data as any).redirect_browser_to
return
case "session_already_available":
await fetch('/.ory/kratos/public/sessions/whoami')
.then(response => response.json())
.then((jsonResponse) => handleAal2Error(jsonResponse, router))
.catch(() => { router.push("/cognition") });
// User is already signed in, let's redirect them home!
await router.push("/cognition")
return
Expand Down
2 changes: 1 addition & 1 deletion submodules/javascript-functions
2 changes: 1 addition & 1 deletion submodules/react-components