Skip to content

Commit 14eafc4

Browse files
committed
login verification form
1 parent 2257901 commit 14eafc4

File tree

2 files changed

+118
-27
lines changed

2 files changed

+118
-27
lines changed

apps/gifting-concierge/src/app/(auth)/login/login-form.tsx

Lines changed: 101 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,137 @@
22

33
import Link from "next/link";
44

5-
import { Button } from "@theliaison/ui/button";
5+
//import { Button } from "@theliaison/ui/button";
6+
import { useState } from "react";
67
import {
78
Card,
89
CardContent,
910
CardDescription,
1011
CardHeader,
1112
CardTitle,
1213
} from "@theliaison/ui/card";
13-
import { Input } from "@theliaison/ui/input";
14+
import { Button, Input } from "@nextui-org/react";
1415
import { Label } from "@theliaison/ui/label";
16+
import { createClient } from "~/supabase/client";
17+
import { redirect } from "next/navigation";
18+
1519
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+
1641
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> :
17102
<Card className="mx-auto max-w-sm backdrop-blur-2xl bg-white/20 border-transparent shadow-sm">
18103
<CardHeader>
19-
<CardTitle className="text-2xl text-black">Login</CardTitle>
104+
<CardTitle className="text-2xl text-black">Verify Email</CardTitle>
20105
<CardDescription className="text-black">
21-
Enter your email below to login to your account
106+
Please enter the OTP sent to your email address
22107
</CardDescription>
23108
</CardHeader>
24109
<CardContent>
110+
<form action={verifyOTPAction}>
25111
<div className="grid gap-4">
26112
<div className="grid gap-2">
27-
<Label htmlFor="email">Email</Label>
28113
<Input
29114
id="email"
30-
type="email"
31-
placeholder="m@example.com"
115+
type="text"
116+
name="otp"
117+
placeholder="Enter your OTP"
32118
className="border-black text-black placeholder:text-black/90"
33119
required
34120
/>
35121
</div>
36-
<div className="grid gap-2">
37-
<div className="flex items-center">
122+
{/* <div className="flex items-center">
38123
<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">
40125
Forgot your password?
41126
</Link>
42-
</div>
43-
<Input
44-
id="password"
45-
type="password"
46-
required
47-
className="border-black text-black"
48-
/>
49-
</div>
127+
</div> */}
50128
<Button type="submit" className="w-full bg-black">
51-
Login
129+
Verify
52130
</Button>
53131
</div>
54-
<div className="mt-4 text-center text-sm">
55-
Don&apos;t have an account?{" "}
56-
<Link href="/register" className="underline">
57-
Register
58-
</Link>
59-
</div>
132+
</form>
60133
</CardContent>
61134
</Card>
62-
);
135+
}
136+
</>
137+
)
63138
}

apps/gifting-concierge/src/app/confirm/[giftId]/confirm-gift.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { Step, Stepper, useStepper } from "@theliaison/ui/stepper";
99
import { ChevronRightIcon } from "lucide-react";
1010
import Link from "next/link";
1111
import { useConfirmDialogStore } from "~/store/confirm-dialog";
12+
import { createClient } from '@supabase/supabase-js';
13+
import { LoginForm } from "~/app/(auth)/login/login-form";
14+
1215

1316
const steps: { label: string; description: string }[] = [
1417
{
@@ -110,13 +113,14 @@ function StepperConfirmGift({ children }: { children: React.ReactNode }) {
110113
<Step key={stepProps.label}>
111114
<div
112115
className={cn(
113-
"min-h-40 h-auto flex items-center justify-center my-2 border bg-foreground text-primary rounded-md p-4",
116+
"min-h-40 h-auto flex items-center justify-center my-2 border bg-white text-primary rounded-md p-4",
114117
{
115118
"bg-transparent": index === 2,
116119
},
117120
)}
118121
>
119122
{index === 0 ? <FirstStepConfirmGift /> : null}
123+
{index === 1 ? <LoginForm/> : null}
120124
{index === 2 ? children : null}
121125
</div>
122126
</Step>
@@ -218,3 +222,15 @@ function FirstStepConfirmGift() {
218222
</div>
219223
);
220224
}
225+
226+
function LoginButton() {
227+
// const origin = window.location.origin
228+
// return (
229+
// <div className="flex flex-col gap-2">
230+
// <p>You need to log in</p>
231+
// <Button onClick={() => window.open(`${origin}/login`, '_blank')}>
232+
// Login
233+
// </Button>
234+
// </div>
235+
// )
236+
}

0 commit comments

Comments
 (0)