|
| 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 | +} |
0 commit comments