diff options
Diffstat (limited to 'communities/red-right-hand/174bg.net/src/app')
3 files changed, 68 insertions, 0 deletions
diff --git a/communities/red-right-hand/174bg.net/src/app/api/auth/[...all]/route.js b/communities/red-right-hand/174bg.net/src/app/api/auth/[...all]/route.js new file mode 100644 index 0000000..2aabedd --- /dev/null +++ b/communities/red-right-hand/174bg.net/src/app/api/auth/[...all]/route.js @@ -0,0 +1,4 @@ +import { auth } from "@/auth"; +import { toNextJsHandler } from "better-auth/next-js"; + +export const { POST, GET } = toNextJsHandler(auth); diff --git a/communities/red-right-hand/174bg.net/src/app/login/page.js b/communities/red-right-hand/174bg.net/src/app/login/page.js new file mode 100644 index 0000000..b2b1ea8 --- /dev/null +++ b/communities/red-right-hand/174bg.net/src/app/login/page.js @@ -0,0 +1,51 @@ +"use client"; + +import { Suspense, useEffect, useState } from "react"; +import { useSearchParams } from "next/navigation"; +import { authClient } from "@/lib/auth-client"; + +function LoginRedirect() { + const searchParams = useSearchParams(); + const callbackUrl = searchParams.get("callbackUrl") ?? "/secure"; + const [error, setError] = useState(null); + + const signIn = () => { + authClient.signIn + .social({ + provider: "discord", + callbackURL: callbackUrl, + }) + .then(({ error }) => { + if (error) setError(error.message ?? "Sign-in failed"); + }); + }; + + useEffect(() => { + signIn(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + + if (error) { + return ( + <div> + <p>Error: {error}</p> + <button onClick={signIn}>Retry</button> + </div> + ); + } + + return ( + <div> + <p>Redirecting to Discord...</p> + <button onClick={signIn}>Click here if nothing happens</button> + </div> + ); +} + +export default function LoginPage() { + return ( + <Suspense fallback={<p>Loading...</p>}> + <LoginRedirect /> + </Suspense> + ); +} diff --git a/communities/red-right-hand/174bg.net/src/app/secure/page.js b/communities/red-right-hand/174bg.net/src/app/secure/page.js new file mode 100644 index 0000000..27312b7 --- /dev/null +++ b/communities/red-right-hand/174bg.net/src/app/secure/page.js @@ -0,0 +1,13 @@ +import { auth } from "@/auth"; +import { headers } from "next/headers"; + +export default async function SecurePage() { + const session = await auth.api.getSession({ headers: await headers() }); + + return ( + <main> + <h1>Secure Area</h1> + <p>Welcome, {session?.user?.name ?? session?.user?.email}!</p> + </main> + ); +} |
