diff --git a/src/routes/login.tsx b/src/routes/login.tsx index f30a8c4..e108cc5 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 = '帳號或密碼錯誤'; }