|
2 | 2 |
|
3 | 3 | import Link from "next/link";
|
4 | 4 |
|
5 |
| -import { Button } from "@theliaison/ui/button"; |
| 5 | +//import { Button } from "@theliaison/ui/button"; |
| 6 | +import { useState } from "react"; |
6 | 7 | import {
|
7 | 8 | Card,
|
8 | 9 | CardContent,
|
9 | 10 | CardDescription,
|
10 | 11 | CardHeader,
|
11 | 12 | CardTitle,
|
12 | 13 | } from "@theliaison/ui/card";
|
13 |
| -import { Input } from "@theliaison/ui/input"; |
| 14 | +import { Button, Input } from "@nextui-org/react"; |
14 | 15 | import { Label } from "@theliaison/ui/label";
|
| 16 | +import { createClient } from "~/supabase/client"; |
| 17 | +import { redirect } from "next/navigation"; |
| 18 | + |
15 | 19 | export function LoginForm() {
|
| 20 | + |
| 21 | + const [login, setLogin ] = useState<boolean>(false) |
| 22 | + const [email, setEmail ] = useState<string>('') |
| 23 | + |
| 24 | + const signInWithEmailAction = async (formData: FormData) => { |
| 25 | + const email = formData.get("email") as string; |
| 26 | + const supabase = createClient(); |
| 27 | + |
| 28 | + const { error } = await supabase.auth.signInWithOtp({ |
| 29 | + email, |
| 30 | + }); |
| 31 | + |
| 32 | + if (error) { |
| 33 | + console.log(error); |
| 34 | + } |
| 35 | + |
| 36 | + //redirect(`/login/verify?email=${email}`); |
| 37 | + setEmail(email) |
| 38 | + setLogin(true) |
| 39 | + }; |
| 40 | + |
16 | 41 | return (
|
| 42 | + <> |
| 43 | + { |
| 44 | + login ? <VerifyOTP email={email}/> : |
| 45 | + <Card className="mx-auto max-w-sm backdrop-blur-2xl bg-white/20 border-transparent shadow-sm"> |
| 46 | + <CardHeader> |
| 47 | + <CardTitle className="text-2xl text-black">Login</CardTitle> |
| 48 | + <CardDescription className="text-black"> |
| 49 | + Enter your email below to login to your account |
| 50 | + </CardDescription> |
| 51 | + </CardHeader> |
| 52 | + <CardContent> |
| 53 | + <form action={signInWithEmailAction}> |
| 54 | + <div className="grid gap-4"> |
| 55 | + <div className="grid gap-2"> |
| 56 | + <Label className="text-black" htmlFor="email">Email</Label> |
| 57 | + <Input |
| 58 | + id="email" |
| 59 | + type="email" |
| 60 | + name="email" |
| 61 | + placeholder="m@example.com" |
| 62 | + className="border-black text-black placeholder:text-black/90" |
| 63 | + required |
| 64 | + /> |
| 65 | + </div> |
| 66 | + <Button type="submit" className="w-full bg-black"> |
| 67 | + Login |
| 68 | + </Button> |
| 69 | + </div> |
| 70 | + </form> |
| 71 | + </CardContent> |
| 72 | + </Card> |
| 73 | + |
| 74 | + } |
| 75 | + </> |
| 76 | + ); |
| 77 | +} |
| 78 | + |
| 79 | +function VerifyOTP({email}:{email: string}) { |
| 80 | + |
| 81 | + const [verify, setVerify ] = useState<boolean>(false) |
| 82 | + |
| 83 | + const verifyOTPAction = async (formData: FormData) => { |
| 84 | + |
| 85 | + const otp = formData.get("otp") as string; |
| 86 | + const supabase = createClient(); |
| 87 | + |
| 88 | + const { error, data } = await supabase.auth.verifyOtp({ |
| 89 | + email, |
| 90 | + token: otp, |
| 91 | + type: "email", |
| 92 | + }); |
| 93 | + console.log('hola') |
| 94 | + |
| 95 | + console.log({ error, data }); |
| 96 | + if (!error) setVerify(true) |
| 97 | + }; |
| 98 | + return( |
| 99 | + <> |
| 100 | + { |
| 101 | + verify ? <h1>Verify Email</h1> : |
17 | 102 | <Card className="mx-auto max-w-sm backdrop-blur-2xl bg-white/20 border-transparent shadow-sm">
|
18 | 103 | <CardHeader>
|
19 |
| - <CardTitle className="text-2xl text-black">Login</CardTitle> |
| 104 | + <CardTitle className="text-2xl text-black">Verify Email</CardTitle> |
20 | 105 | <CardDescription className="text-black">
|
21 |
| - Enter your email below to login to your account |
| 106 | + Please enter the OTP sent to your email address |
22 | 107 | </CardDescription>
|
23 | 108 | </CardHeader>
|
24 | 109 | <CardContent>
|
| 110 | + <form action={verifyOTPAction}> |
25 | 111 | <div className="grid gap-4">
|
26 | 112 | <div className="grid gap-2">
|
27 |
| - <Label htmlFor="email">Email</Label> |
28 | 113 | <Input
|
29 | 114 | id="email"
|
30 |
| - type="email" |
31 |
| - placeholder="m@example.com" |
| 115 | + type="text" |
| 116 | + name="otp" |
| 117 | + placeholder="Enter your OTP" |
32 | 118 | className="border-black text-black placeholder:text-black/90"
|
33 | 119 | required
|
34 | 120 | />
|
35 | 121 | </div>
|
36 |
| - <div className="grid gap-2"> |
37 |
| - <div className="flex items-center"> |
| 122 | + {/* <div className="flex items-center"> |
38 | 123 | <Label htmlFor="password">Password</Label>
|
39 |
| - <Link href="#" className="ml-auto inline-block text-sm underline"> |
| 124 | + <Link href="#" className="ml-auto inline-block text-sm text-black underline"> |
40 | 125 | Forgot your password?
|
41 | 126 | </Link>
|
42 |
| - </div> |
43 |
| - <Input |
44 |
| - id="password" |
45 |
| - type="password" |
46 |
| - required |
47 |
| - className="border-black text-black" |
48 |
| - /> |
49 |
| - </div> |
| 127 | + </div> */} |
50 | 128 | <Button type="submit" className="w-full bg-black">
|
51 |
| - Login |
| 129 | + Verify |
52 | 130 | </Button>
|
53 | 131 | </div>
|
54 |
| - <div className="mt-4 text-center text-sm"> |
55 |
| - Don't have an account?{" "} |
56 |
| - <Link href="/register" className="underline"> |
57 |
| - Register |
58 |
| - </Link> |
59 |
| - </div> |
| 132 | + </form> |
60 | 133 | </CardContent>
|
61 | 134 | </Card>
|
62 |
| - ); |
| 135 | + } |
| 136 | + </> |
| 137 | + ) |
63 | 138 | }
|
0 commit comments