From 42bfd80cefba71621fc420b197dd59d7d70cf3c6 Mon Sep 17 00:00:00 2001 From: an920107 Date: Sat, 2 Nov 2024 19:04:25 +0800 Subject: [PATCH 1/2] feat: sign in page frontend --- src/routes/login.tsx | 95 +++++++++++++++++++++++++++++++++----------- 1 file changed, 72 insertions(+), 23 deletions(-) diff --git a/src/routes/login.tsx b/src/routes/login.tsx index f30a8c4..d9b7567 100644 --- a/src/routes/login.tsx +++ b/src/routes/login.tsx @@ -1,7 +1,6 @@ -import { createFileRoute } from '@tanstack/react-router' -import { useState } from 'react' -import { VStack } from '../components' -import { supabase } from '../utils/supabase' +import { createFileRoute } from '@tanstack/react-router'; +import { useState } from 'react'; +import { supabase } from '../utils/supabase'; export const Route = createFileRoute('/login')({ component: LoginPage, @@ -15,16 +14,17 @@ export const Route = createFileRoute('/login')({ function LoginPage() { const [email, setEmail] = useState('') const [password, setPassword] = useState('') + const [isRemember, setIsRemember] = useState(false); + const [isError, setIsError] = useState(false); const { redirect: redirectUrl } = Route.useSearch() - async function login() { - const { data: { session }, error } = await supabase.auth.signInWithPassword({ - email, - password - }) + async function login(event: React.FormEvent) { + event.preventDefault(); + const { data: { session }, error } = await supabase.auth.signInWithPassword({ email, password }); if (error !== null) { - throw error + setPassword(''); + setIsError(true); } if (session !== null) { @@ -33,19 +33,68 @@ function LoginPage() { } return ( -
- -
- - { setEmail(e.target.value) }} /> -
-
- - { setPassword(e.target.value) }} /> -
-
- -
+
+ setEmail(e.target.value)} + /> + setPassword(e.target.value)} + /> +
+ {/* The style of the checkbox is refered from https://www.material-tailwind.com/docs/html/checkbox */} + + +
+ { + isError + ? ( + + {isError ? Labels.wrongAccountOrPassword : ''} + + ) + : <> + } + +
) +} + +class Labels { + private constructor() { } + static readonly account = '信箱或手機號碼'; + static readonly password = '密碼'; + static readonly remember = '保持我的登入狀態'; + static readonly login = '登入'; + static readonly wrongAccountOrPassword = '帳號或密碼錯誤'; } From b9317a17e447041d03d274ac2b884a57513eed73 Mon Sep 17 00:00:00 2001 From: Susan Chen <92381825+1989ONCE@users.noreply.github.com> Date: Wed, 27 Nov 2024 14:37:55 +0800 Subject: [PATCH 2/2] Update src/routes/login.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- src/routes/login.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/login.tsx b/src/routes/login.tsx index d9b7567..e108cc5 100644 --- a/src/routes/login.tsx +++ b/src/routes/login.tsx @@ -61,8 +61,8 @@ function LoginPage() { onChange={(e) => setIsRemember(e.target.checked)} /> - - +