From 7a98ed92fb3441826aa6af13993f6c6614e522b6 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Mon, 8 Feb 2021 17:14:51 +0100 Subject: [PATCH] error page --- packages/dashboard/src/pages/error.js | 52 +++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 packages/dashboard/src/pages/error.js diff --git a/packages/dashboard/src/pages/error.js b/packages/dashboard/src/pages/error.js new file mode 100644 index 00000000..36fb4803 --- /dev/null +++ b/packages/dashboard/src/pages/error.js @@ -0,0 +1,52 @@ +import Link from "next/link"; +import { Configuration, PublicApi } from "@ory/kratos-client"; +import config from "../config"; + +const kratos = new PublicApi(new Configuration({ basePath: config.kratos.public })); + +export async function getServerSideProps(context) { + const error = req.query.error; + + // No error was send, redirecting back to home. + if (!error || typeof error !== "string") { + console.log("No error ID found in URL, redirecting to homepage."); + + return { redirect: { permanent: false, destination: config.kratos.browser } }; + } + + try { + const { status, data } = await kratos.getSelfServiceError(error); + + if ("errors" in data) return { props: { errors: data.errors } }; + + throw new Error(`Expected error ${error} to contain "errors" but got ${JSON.stringify(data)}`); + } catch (error) { + return { redirect: { permanent: false, destination: config.kratos.browser } }; + } +} + +export default function Error({ errors }) { + return ( +
+
+ + + +

An error occurred

+
+
+
{JSON.stringify(errors)}
+
+
+ ); +}