cg / hackerproducts

63 files · 5,740 lines · 159.1 KB — Next.js 15, React 19, TypeScript, PostgreSQL, Object Storage, plain CSS.

Quick jump: page.tsx / page.tsx / globals.css / schema.sql / package.json

root / src / app / login / page.tsx

src/app/login/page.tsx · 85 lines · 2.2 KB← back to folder
1import type { Metadata } from "next";
2import { redirect } from "next/navigation";
3import { getAuthProviders, getCurrentUser } from "@/lib/auth";
4import { CredentialsAuthForm } from "@/components/CredentialsAuthForm";
5import { DevLoginForm } from "@/components/DevLoginForm";
6
7export const dynamic = "force-dynamic";
8
9export const metadata: Metadata = {
10 title: "Sign in",
11 robots: { index: false, follow: false },
12};
13
14export default async function LoginPage({
15 searchParams,
16}: {
17 searchParams: Promise<{ next?: string; error?: string }>;
18}) {
19 const user = await getCurrentUser();
20 const params = await searchParams;
21 const next =
22 params.next && params.next.startsWith("/") && !params.next.startsWith("//")
23 ? params.next
24 : "/";
25
26 if (user) {
27 redirect(next);
28 }
29
30 const providers = getAuthProviders();
31
32 return (
33 <div>
34 <h1>Sign in</h1>
35 <p className="subtitle">
36 Sign in or create an account to submit products and upvote projects.
37 </p>
38
39 {params.error && (
40 <p className="form-error" role="alert">
41 Sign in failed ({params.error.replace(/_/g, " ")}). Please try again.
42 </p>
43 )}
44
45 <CredentialsAuthForm next={next} />
46
47 {(providers.github || providers.google) && (
48 <div
49 style={{
50 marginTop: 28,
51 paddingTop: 20,
52 borderTop: "1px solid #e5e5e5",
53 display: "flex",
54 flexDirection: "column",
55 gap: 10,
56 maxWidth: 380,
57 }}
58 >
59 {providers.github && (
60 <a
61 href={`/api/auth/github?next=${encodeURIComponent(next)}`}
62 className="btn-secondary"
63 style={{ textAlign: "center", textDecoration: "none", color: "#111111" }}
64 >
65 Continue with GitHub
66 </a>
67 )}
68
69 {providers.google && (
70 <a
71 href={`/api/auth/google?next=${encodeURIComponent(next)}`}
72 className="btn-secondary"
73 style={{ textAlign: "center", textDecoration: "none", color: "#111111" }}
74 >
75 Continue with Google
76 </a>
77 )}
78 </div>
79 )}
80
81 {providers.dev && <DevLoginForm next={next} />}
82 </div>
83 );
84}
85
cg / hackerproducts — hacker products