|
1 | | -import Link from "next/link"; |
2 | | -import { headers, cookies } from "next/headers"; |
3 | | -import { createClient } from "@/utils/supabase/server"; |
4 | | -import { redirect } from "next/navigation"; |
| 1 | +import Checkbox from './components/Checkbox'; |
| 2 | +import { signIn } from '@/utils/supabase/auth'; |
| 3 | +import Link from 'next/link'; |
| 4 | +import ETS from '../../public/ETS.svg'; |
| 5 | +import PasswordInput from './components/PasswordInput'; |
| 6 | +import Alert from '@/components/Alert'; |
| 7 | +import { faTriangleExclamation } from '@fortawesome/free-solid-svg-icons'; |
5 | 8 |
|
6 | | -export default function Login({ |
7 | | - searchParams, |
8 | | -}: { |
9 | | - searchParams: { message: string }; |
10 | | -}) { |
11 | | - const signIn = async (formData: FormData) => { |
12 | | - "use server"; |
| 9 | +export default function Login({ searchParams }: { searchParams: { message: string; type: string } }) { |
| 10 | + return ( |
| 11 | + <div className='animate-in relative flex justify-center items-center rounded-2xl w-screen h-screen'> |
| 12 | + <div className={`absolute bottom-4 right-4 w-[141px] h-[79px] bg-[url('../public/ETS.svg')] bg-cover`} /> |
| 13 | + <div className='grid justify-items-center content-center bg-accent rounded-2xl min-h-min min-w-min '> |
| 14 | + <h1 className='py-10 text-4xl'>Bienvenue !</h1> |
| 15 | + <div className='flex-1 flex flex-col w-full px-8 sm:max-w-md justify-center gap-2'> |
| 16 | + <form className='flex-1 flex flex-col w-full justify-center gap-2 text-foreground' action={signIn}> |
| 17 | + {searchParams?.message && ( |
| 18 | + <Alert |
| 19 | + customStyle={'flex flex-1 flex-col w-full pb-2 justify-center gap-2'} |
| 20 | + text={searchParams.message} |
| 21 | + alertType={searchParams.type} |
| 22 | + icon={faTriangleExclamation} |
| 23 | + /> |
| 24 | + )} |
| 25 | + <label className='text-md text-primary' htmlFor='email'> |
| 26 | + Courriel |
| 27 | + </label> |
| 28 | + <input className='rounded-md px-4 py-2 bg-inherit border mb-6' name='email' required /> |
| 29 | + <label className='text-md text-primary' htmlFor='password'> |
| 30 | + Mot de passe |
| 31 | + </label> |
| 32 | + <PasswordInput /> |
| 33 | + <Checkbox |
| 34 | + checked={true} |
| 35 | + style='self-end pb-6' |
| 36 | + text='Se souvenir de moi' |
| 37 | + textStyle='text-primary' |
| 38 | + checkboxStyle='checkbox-primary' |
| 39 | + /> |
| 40 | + <button className='btn btn-ghost bg-secondary rounded-md text-foreground text-base mb-2 hover:bg-secondary/75'> |
| 41 | + Se connecter |
| 42 | + </button> |
| 43 | + </form> |
13 | 44 |
|
14 | | - const email = formData.get("email") as string; |
15 | | - const password = formData.get("password") as string; |
16 | | - const cookieStore = cookies(); |
17 | | - const supabase = createClient(cookieStore); |
18 | | - |
19 | | - const { error } = await supabase.auth.signInWithPassword({ |
20 | | - email, |
21 | | - password, |
22 | | - }); |
23 | | - |
24 | | - if (error) { |
25 | | - return redirect("/login?message=Could not authenticate user"); |
26 | | - } |
27 | | - |
28 | | - return redirect("/"); |
29 | | - }; |
30 | | - |
31 | | - const signUp = async (formData: FormData) => { |
32 | | - "use server"; |
33 | | - |
34 | | - const origin = headers().get("origin"); |
35 | | - const email = formData.get("email") as string; |
36 | | - const password = formData.get("password") as string; |
37 | | - const cookieStore = cookies(); |
38 | | - const supabase = createClient(cookieStore); |
39 | | - |
40 | | - const { error } = await supabase.auth.signUp({ |
41 | | - email, |
42 | | - password, |
43 | | - options: { |
44 | | - emailRedirectTo: `${origin}/auth/callback`, |
45 | | - }, |
46 | | - }); |
47 | | - |
48 | | - if (error) { |
49 | | - return redirect("/login?message=Could not authenticate user"); |
50 | | - } |
51 | | - |
52 | | - return redirect("/login?message=Check email to continue sign in process"); |
53 | | - }; |
54 | | - |
55 | | - return ( |
56 | | - <div className="flex-1 flex flex-col w-full px-8 sm:max-w-md justify-center gap-2"> |
57 | | - <Link |
58 | | - href="/" |
59 | | - 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" |
60 | | - > |
61 | | - <svg |
62 | | - xmlns="http://www.w3.org/2000/svg" |
63 | | - width="24" |
64 | | - height="24" |
65 | | - viewBox="0 0 24 24" |
66 | | - fill="none" |
67 | | - stroke="currentColor" |
68 | | - strokeWidth="2" |
69 | | - strokeLinecap="round" |
70 | | - strokeLinejoin="round" |
71 | | - className="mr-2 h-4 w-4 transition-transform group-hover:-translate-x-1" |
72 | | - > |
73 | | - <polyline points="15 18 9 12 15 6" /> |
74 | | - </svg>{" "} |
75 | | - Back |
76 | | - </Link> |
77 | | - |
78 | | - <form |
79 | | - className="animate-in flex-1 flex flex-col w-full justify-center gap-2 text-foreground" |
80 | | - action={signIn} |
81 | | - > |
82 | | - <label className="text-md" htmlFor="email"> |
83 | | - Email |
84 | | - </label> |
85 | | - <input |
86 | | - className="rounded-md px-4 py-2 bg-inherit border mb-6" |
87 | | - name="email" |
88 | | - |
89 | | - required |
90 | | - /> |
91 | | - <label className="text-md" htmlFor="password"> |
92 | | - Password |
93 | | - </label> |
94 | | - <input |
95 | | - className="rounded-md px-4 py-2 bg-inherit border mb-6" |
96 | | - type="password" |
97 | | - name="password" |
98 | | - placeholder="••••••••" |
99 | | - required |
100 | | - /> |
101 | | - <button className="bg-green-700 rounded-md px-4 py-2 text-foreground mb-2"> |
102 | | - Sign In |
103 | | - </button> |
104 | | - <button |
105 | | - formAction={signUp} |
106 | | - className="border border-foreground/20 rounded-md px-4 py-2 text-foreground mb-2" |
107 | | - > |
108 | | - Sign Up |
109 | | - </button> |
110 | | - {searchParams?.message && ( |
111 | | - <p className="mt-4 p-4 bg-foreground/10 text-foreground text-center"> |
112 | | - {searchParams.message} |
113 | | - </p> |
114 | | - )} |
115 | | - </form> |
116 | | - </div> |
117 | | - ); |
| 45 | + <div className='flex justify-center'> |
| 46 | + <p className='text-xs text-primary'> |
| 47 | + Vous avez oublié vos informations? |
| 48 | + <Link href={'/forgotPassword'} className='text-xs pl-1 underline text-secondary'> |
| 49 | + Réinitialisez votre mot de passe |
| 50 | + </Link> |
| 51 | + </p> |
| 52 | + </div> |
| 53 | + <div className='flex justify-center'> |
| 54 | + <p className='text-xs pb-10 text-primary'> |
| 55 | + Vous n'avez pas de compte? |
| 56 | + <Link href={'/signUp'} className='text-xs pl-1 underline text-secondary'> |
| 57 | + Inscrivez-vous |
| 58 | + </Link> |
| 59 | + </p> |
| 60 | + </div> |
| 61 | + </div> |
| 62 | + </div> |
| 63 | + </div> |
| 64 | + ); |
118 | 65 | } |
0 commit comments