-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSignInForm.tsx
More file actions
104 lines (99 loc) · 2.84 KB
/
SignInForm.tsx
File metadata and controls
104 lines (99 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { SignInMethodDivider } from "@/components/SignInMethodDivider";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Toaster } from "@/components/ui/toaster";
import { useToast } from "@/components/ui/use-toast";
import { useAuthActions } from "@convex-dev/auth/react";
import { GitHubLogoIcon } from "@radix-ui/react-icons";
import { useState } from "react";
import { GoogleLogo } from "./components/GoogleLogo";
export function SignInForm() {
const [step, setStep] = useState<"signIn" | "linkSent">("signIn");
return (
<div className="">
<div className="w-[350px] md:w-[450px] mx-auto flex flex-col my-auto gap-4 p-4">
{step === "signIn" ? (
<div>
<div className="flex flex-col gap-2">
<SignInWithGitHub />
<SignInWithGoogle />
</div>
{/* <SignInMethodDivider />
<SignInWithMagicLink handleLinkSent={() => setStep("linkSent")} /> */}
</div>
) : (
<>
<h2 className="font-semibold text-2xl tracking-tight">
Check your email
</h2>
<p>A sign-in link has been sent to your email address.</p>
<Button
className="p-0 self-start"
variant="link"
onClick={() => setStep("signIn")}
>
Cancel
</Button>
</>
)}
</div>
</div>
);
}
export function SignInWithGitHub() {
const { signIn } = useAuthActions();
return (
<Button
className="flex-1"
variant="outline"
type="button"
onClick={() => void signIn("github")}
>
<GitHubLogoIcon className="mr-2 h-4 w-4" /> GitHub
</Button>
);
}
export function SignInWithGoogle() {
const { signIn } = useAuthActions();
return (
<Button
className="flex-1"
variant="outline"
type="button"
onClick={() => void signIn("google")}
>
<GoogleLogo className="mr-2 h-4 w-4" /> Google
</Button>
);
}
function SignInWithMagicLink({
handleLinkSent,
}: {
handleLinkSent: () => void;
}) {
const { signIn } = useAuthActions();
const { toast } = useToast();
return (
<form
className="flex flex-col"
onSubmit={(event) => {
event.preventDefault();
const formData = new FormData(event.currentTarget);
signIn("resend", formData)
.then(handleLinkSent)
.catch((error) => {
console.error(error);
toast({
title: "Could not send sign-in link",
variant: "destructive",
});
});
}}
>
<label htmlFor="email">Email</label>
<Input name="email" id="email" className="mb-4" autoComplete="email" />
<Button type="submit">Send sign-in link</Button>
<Toaster />
</form>
);
}