Source: pages/auth/error.jsx

  1. /** @module pages/api/auth/error */
  2. import { Box, Button, Card, Heading, Text } from "grommet";
  3. import Head from "next/head";
  4. import { useRouter } from "next/router";
  5. import Clouds from "../../components/clouds";
  6. import { Logo } from "../../components/logo";
  7. import { NEXT_AUTH_ERRORS, _NEXT_AUTH_ERRORS } from "../../lib/errors";
  8. import { useTranslation } from "next-i18next";
  9. import { serverSideTranslations } from "next-i18next/serverSideTranslations";
  10. /**
  11. * This page is shown when the user encounters an error while signing up or signing in.
  12. */
  13. export default function Error() {
  14. const { query, push, locale } = useRouter();
  15. const { t } = useTranslation("errors");
  16. const { error: errorCode } = query;
  17. console.error({
  18. service: "web",
  19. pathname: "/auth/error",
  20. component: "VerifyRequest",
  21. error_message: _NEXT_AUTH_ERRORS[errorCode],
  22. });
  23. return (
  24. <>
  25. <Head>
  26. <title>{t("errored")}</title>
  27. </Head>
  28. <Clouds />
  29. <Box
  30. pad="large"
  31. align="center"
  32. gap="medium"
  33. width="large"
  34. justify="center"
  35. style={{
  36. display: "flex",
  37. height: "90vh",
  38. margin: "auto",
  39. }}
  40. >
  41. <Card
  42. pad="large"
  43. gap="medium"
  44. align="center"
  45. background="white"
  46. style={{
  47. minWidth: "24rem",
  48. }}
  49. >
  50. <Logo />
  51. <Heading
  52. level={2}
  53. style={{
  54. marginBottom: 0,
  55. }}
  56. >
  57. {t("errored")}
  58. </Heading>
  59. <Text
  60. style={{
  61. marginBottom: "1.5rem",
  62. }}
  63. >
  64. {NEXT_AUTH_ERRORS[errorCode][locale]}
  65. </Text>
  66. <Button
  67. key={"back-to-site"}
  68. style={{
  69. width: "100%",
  70. }}
  71. onClick={() => push(`/${locale}`)}
  72. label={t("back-to-site")}
  73. primary
  74. />
  75. </Card>
  76. </Box>
  77. </>
  78. );
  79. }
  80. export async function getServerSideProps(context) {
  81. return {
  82. props: {
  83. ...(await serverSideTranslations(context.locale, ["errors", "common"])),
  84. },
  85. };
  86. }