diff --git a/src/app/(auth)/components/index.tsx b/src/app/(auth)/components/index.tsx index fbe5ae4e..fd2fdacc 100644 --- a/src/app/(auth)/components/index.tsx +++ b/src/app/(auth)/components/index.tsx @@ -1,6 +1,6 @@ "use client" -import { startTransition, useEffect, useState } from "react" +import { startTransition, Suspense, useEffect, useState } from "react" import styles from "./auth.module.css" import Link from "../../components/link" import { signIn } from "next-auth/react" @@ -8,8 +8,9 @@ import Input from "@components/input" import Button from "@components/button" import { GitHub } from "react-feather" import { useToasts } from "@components/toasts" -import { useRouter, useSearchParams } from "next/navigation" +import { useRouter } from "next/navigation" import Note from "@components/note" +import { ErrorQueryParamsHandler } from "./query-handler" function Auth({ page, @@ -28,16 +29,6 @@ function Auth({ const [username, setUsername] = useState("") const [password, setPassword] = useState("") const [submitting, setSubmitting] = useState(false) - const queryParams = useSearchParams() - - useEffect(() => { - if (queryParams.get("error")) { - setToast({ - message: queryParams.get("error") as string, - type: "error" - }) - } - }, [queryParams, setToast]) async function handleSubmit(event: React.FormEvent) { event.preventDefault() @@ -81,6 +72,10 @@ function Auth({ return (
+ {/* Suspense boundary because useSearchParams causes static bailout */} + + +

Sign {signText}

diff --git a/src/app/(auth)/components/query-handler.tsx b/src/app/(auth)/components/query-handler.tsx new file mode 100644 index 00000000..9864b5c5 --- /dev/null +++ b/src/app/(auth)/components/query-handler.tsx @@ -0,0 +1,21 @@ +"use client" + +import { useToasts } from "@components/toasts" +import { useSearchParams } from "next/navigation" +import { useEffect } from "react" + +export function ErrorQueryParamsHandler() { + const queryParams = useSearchParams() + const { setToast } = useToasts() + + useEffect(() => { + if (queryParams.get("error")) { + setToast({ + message: queryParams.get("error") as string, + type: "error" + }) + } + }, [queryParams, setToast]) + + return null +}