Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 02d1842

Browse files
Merge pull request #12 from Altroleum/sign-up
add basic sign up page
2 parents 1326df7 + 6251b2f commit 02d1842

3 files changed

Lines changed: 1081 additions & 23 deletions

File tree

app/create/page.tsx

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
"use client";
2+
3+
import BackengineLogo from "@/components/BackengineLogo";
4+
import { createClientComponentClient } from "@supabase/auth-helpers-nextjs";
5+
import Link from "next/link";
6+
import { useState } from "react";
7+
8+
function GoBack() {
9+
return (
10+
<Link
11+
href="/"
12+
className="absolute left-8 top-8 py-2 px-4 rounded-md no-underline text-foreground bg-btn-background hover:bg-btn-background-hover flex items-center group text-sm"
13+
>
14+
<svg
15+
width="24"
16+
height="24"
17+
viewBox="0 0 24 24"
18+
fill="none"
19+
stroke="currentColor"
20+
strokeWidth="2"
21+
strokeLinecap="round"
22+
strokeLinejoin="round"
23+
className="mr-2 h-4 w-4 transition-transform group-hover:-translate-x-1"
24+
>
25+
<polyline points="15 18 9 12 15 6" />
26+
</svg>{" "}
27+
Back
28+
</Link>
29+
);
30+
}
31+
32+
export default function Create() {
33+
const [email, setEmail] = useState("");
34+
const [password, setPassword] = useState("");
35+
const [isCreated, setIsCreated] = useState(false);
36+
const [isLoading, setIsLoading] = useState(false);
37+
const supabase = createClientComponentClient();
38+
39+
const handleCreate = async (e: React.FormEvent<HTMLFormElement>) => {
40+
e.preventDefault();
41+
setIsLoading(true);
42+
const { error } = await supabase.auth.signUp({
43+
email,
44+
password,
45+
});
46+
if (!error) {
47+
setIsCreated(true);
48+
}
49+
setIsLoading(false);
50+
};
51+
52+
if (isCreated) {
53+
return (
54+
<div className="flex-1 flex flex-col w-full px-8 sm:max-w-md justify-center gap-2">
55+
<GoBack />
56+
<div className="text-foreground text-center space-y-2">
57+
<h3 className="text-2xl">Account created!</h3>
58+
<p>Please check your email ({email}) to verify your account.</p>
59+
</div>
60+
</div>
61+
);
62+
}
63+
64+
return (
65+
<div className="flex-1 flex flex-col w-full px-8 sm:max-w-md justify-center gap-2">
66+
<GoBack />
67+
<form
68+
className="flex-1 flex flex-col w-full justify-center gap-2 text-foreground"
69+
onSubmit={handleCreate}
70+
>
71+
<div className="flex justify-center pb-6">
72+
<BackengineLogo />
73+
</div>
74+
<label className="text-md" htmlFor="email">
75+
Email
76+
</label>
77+
<input
78+
disabled={isLoading}
79+
className="rounded-md px-4 py-2 bg-inherit border mb-6"
80+
name="email"
81+
onChange={(e) => setEmail(e.target.value)}
82+
value={email}
83+
placeholder="you@example.com"
84+
/>
85+
<label className="text-md" htmlFor="password">
86+
Password
87+
</label>
88+
<input
89+
disabled={isLoading}
90+
className="rounded-md px-4 py-2 bg-inherit border mb-6"
91+
type="password"
92+
name="password"
93+
onChange={(e) => setPassword(e.target.value)}
94+
value={password}
95+
placeholder="••••••••"
96+
/>
97+
<button
98+
className="bg-green-700 rounded px-4 py-2 text-white mb-6"
99+
disabled={isLoading}
100+
>
101+
{isLoading ? "Creating account..." : "Create Account"}
102+
</button>
103+
</form>
104+
</div>
105+
);
106+
}

app/page.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,23 @@ export default async function Index() {
4040
{!user && (
4141
<>
4242
<p className="mb-12">
43-
Login below to access the generated admin page for your project.
43+
Login or create an account below to access the generated admin
44+
page for your project.
4445
</p>
45-
<Link
46-
href="/login"
47-
className="bg-foreground py-3 px-6 rounded-lg text-sm text-background"
48-
>
49-
Login
50-
</Link>
46+
<div className="space-x-4 w-full flex items-center justify-center">
47+
<Link
48+
href="/login"
49+
className="bg-foreground py-3 px-6 rounded-lg text-sm text-background w-[150px] text-center hover:scale-105 transition-all duration-300"
50+
>
51+
Login
52+
</Link>
53+
<Link
54+
href="/create"
55+
className="bg-foreground py-3 px-6 rounded-lg text-sm text-background w-[150px] text-center hover:scale-105 transition-all duration-300"
56+
>
57+
Create Account
58+
</Link>
59+
</div>
5160
</>
5261
)}
5362
</div>

0 commit comments

Comments
 (0)