|
1 | | -"use client" |
2 | | - |
3 | 1 | import * as React from "react" |
4 | | -import { useAccount, useConnect, useDisconnect } from 'wagmi' |
5 | 2 | import { cn } from "@/lib/utils" |
6 | | -import { Icons } from "@/components/ui/icons" |
7 | 3 | import { Button } from "@/components/ui/button" |
8 | 4 | import { Input } from "@/components/ui/input" |
9 | 5 | import { Label } from "@/components/ui/label" |
10 | | -import { HoverCard, HoverCardContent, HoverCardTrigger } from "@/components/ui/hover-card" |
11 | | -import { WalletButton } from "@/components/wallet-buttons" |
12 | | - |
13 | | -interface UserAuthFormProps extends React.HTMLAttributes<HTMLDivElement> { } |
14 | | - |
15 | | -export default function UserLoginForm({ className, ...props }: UserAuthFormProps) { |
16 | | - const [isLoading, setIsLoading] = React.useState<boolean>(false) |
17 | | - |
18 | | - const account = useAccount() |
19 | | - const { connectors, connect, status, error } = useConnect() |
20 | | - const { disconnect } = useDisconnect() |
21 | | - |
22 | | - async function onSubmit(event: React.SyntheticEvent) { |
23 | | - event.preventDefault() |
24 | | - setIsLoading(true) |
| 6 | +import { getSession, login, logout } from "@/app/auth"; |
| 7 | +import Link from "next/link" |
| 8 | +import { redirect } from "next/navigation" |
25 | 9 |
|
26 | | - setTimeout(() => { |
27 | | - setIsLoading(false) |
28 | | - }, 3000) |
29 | | - } |
30 | | - |
31 | | - const loginButtons = connectors.map((connector) => |
32 | | - connector.name.toLowerCase() === "injected" ? null : ( |
33 | | - <WalletButton |
34 | | - connector={connector} |
35 | | - isLoading={isLoading} |
36 | | - connect={connect} |
37 | | - key={connector.uid} |
38 | | - /> |
39 | | - ) |
40 | | - ); |
41 | 10 |
|
| 11 | +export default function UserRegForm() { |
42 | 12 | return ( |
43 | | - <div className={cn("grid gap-6", className)} {...props}> |
44 | | - |
45 | | - {account.status === 'connected' ? ( |
46 | | - <HoverCard> |
47 | | - <HoverCardTrigger asChild> |
48 | | - <Button variant="destructive" onClick={() => disconnect()}>Disconnect</Button> |
49 | | - </HoverCardTrigger> |
50 | | - <HoverCardContent className="w-80"> |
51 | | - <div className="flex justify-between space-x-4"> |
52 | | - <div className="space-y-1"> |
53 | | - <h4 className="text-sm font-semibold">connected as</h4> |
54 | | - <div className="text-xs"> |
55 | | - {JSON.stringify(account.addresses[0].replaceAll(account.addresses[0].slice(8, 36), '...'))} |
56 | | - </div> |
57 | | - </div> |
58 | | - </div> |
59 | | - </HoverCardContent> |
60 | | - </HoverCard> |
61 | | - ) : ( |
62 | | - <div className="grid gap-1"> |
63 | | - {loginButtons} |
64 | | - </div> |
65 | | - )} |
66 | | - <div className="relative"> |
67 | | - <div className="relative flex justify-center text-xs uppercase"> |
68 | | - <span className="bg-background px-2 text-neutral-500"> |
69 | | - Or continue with |
70 | | - </span> |
| 13 | + <> |
| 14 | + <div className="grid gap-6"> |
| 15 | + <div className="flex justify-start"> |
| 16 | + <Link href="/authentication/walletlogin" className="flex w-fit items-center justify-center gap-1 rounded-full border-2 transition-all h-12 px-6 text-lg text-black border-white bg-white font-paragraph font-semibold tracking-wider hover:drop-shadow-[10px_0_20px_rgba(254,254,254,0.472)]">Wallet Login</Link> |
71 | 17 | </div> |
72 | | - </div> |
73 | | - |
74 | | - <form onSubmit={onSubmit}> |
75 | | - <div className="grid gap-2"> |
76 | | - <div className="grid gap-1"> |
77 | | - <Label className="sr-only" htmlFor="email"> |
78 | | - Email |
79 | | - </Label> |
80 | | - <Input |
81 | | - id="email" |
82 | | - placeholder="name@example.com" |
83 | | - type="email" |
84 | | - autoCapitalize="none" |
85 | | - autoComplete="email" |
86 | | - autoCorrect="off" |
87 | | - disabled={isLoading} |
88 | | - /> |
89 | | - </div> |
90 | | - <div className="grid gap-1"> |
91 | | - <Label className="sr-only" htmlFor="password"> |
92 | | - Password |
93 | | - </Label> |
94 | | - <Input |
95 | | - id="password" |
96 | | - placeholder="******" |
97 | | - type="password" |
98 | | - autoCapitalize="none" |
99 | | - autoComplete="email" |
100 | | - autoCorrect="off" |
101 | | - disabled={isLoading} |
102 | | - /> |
| 18 | + <div className="relative"> |
| 19 | + <div className="relative flex justify-start text-xs uppercase"> |
| 20 | + <span className=" px-2 text-neutral-500"> |
| 21 | + Or continue with |
| 22 | + </span> |
103 | 23 | </div> |
104 | | - <Button disabled={isLoading} className="mt-2"> |
105 | | - {isLoading && ( |
106 | | - <Icons.spinner className="mr-2 h-4 w-4 animate-spin" /> |
107 | | - )} |
108 | | - Sign In with Email |
109 | | - </Button> |
110 | 24 | </div> |
111 | | - </form> |
112 | 25 |
|
113 | | - |
114 | | - </div> |
115 | | - ) |
| 26 | + <form |
| 27 | + action={async (formData) => { |
| 28 | + "use server"; |
| 29 | + await login(formData); |
| 30 | + redirect("/dashboard"); |
| 31 | + }} |
| 32 | + > |
| 33 | + <div className="grid gap-2"> |
| 34 | + <div className="grid gap-1"> |
| 35 | + <Label className="sr-only" htmlFor="email"> |
| 36 | + Email |
| 37 | + </Label> |
| 38 | + <Input |
| 39 | + id="email" |
| 40 | + name="email" |
| 41 | + placeholder="name@example.com" |
| 42 | + type="email" |
| 43 | + autoCapitalize="none" |
| 44 | + autoComplete="email" |
| 45 | + autoCorrect="off" |
| 46 | + /> |
| 47 | + </div> |
| 48 | + <div className="grid gap-1"> |
| 49 | + <Label className="sr-only" htmlFor="password"> |
| 50 | + Password |
| 51 | + </Label> |
| 52 | + <Input |
| 53 | + id="password" |
| 54 | + name="password" |
| 55 | + placeholder="******" |
| 56 | + type="password" |
| 57 | + autoCapitalize="none" |
| 58 | + autoComplete="email" |
| 59 | + autoCorrect="off" |
| 60 | + /> |
| 61 | + </div> |
| 62 | + <Button type="submit" >Log In</Button> |
| 63 | + </div> |
| 64 | + </form> |
| 65 | + </div> |
| 66 | + </>) |
116 | 67 | } |
| 68 | + |
0 commit comments