diff --git a/app/user/auth/login/page.tsx b/app/user/auth/login/page.tsx index 0d87883..5987c06 100644 --- a/app/user/auth/login/page.tsx +++ b/app/user/auth/login/page.tsx @@ -1,104 +1,89 @@ 'use client'; -import { useUser } from '@/app/hooks/useUser'; -import { useRouter } from 'next/navigation'; -import React, { useEffect, useState } from 'react'; -import { getClientCookie } from '@/app/utils/stores/cookieStore'; -import { useAuth } from '@/app/user/auth/context/AuthContext'; -import Input from '@/components/layout/input'; -import { Label } from '@/components/ui/label'; -import { Button } from '@/components/ui/button'; -import Loading from '@/app/components/loading'; -export default function Login() { - const [username, setUsername] = useState(''); - const [password, setPassword] = useState(''); - const [error, setError] = useState(''); - const { login } = useUser(); - const router = useRouter(); - const [authChecked, setAuthChecked] = useState(false); - const [loading, setLoading] = useState(true); - const { isLoggedIn } = useAuth(); +import Logo from '@/components/logo'; +import { Button } from '@/components/ui/button'; +import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; +import { Form, FormControl, FormField, FormItem, FormLabel } from '@/components/ui/form'; +import { Input } from '@/components/ui/input'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { useForm } from 'react-hook-form'; +import { z } from 'zod'; - useEffect(() => { - setAuthChecked(true); - }, [isLoggedIn]); - useEffect(() => { - if (authChecked && isLoggedIn) { - router.push('/'); - } - }, [authChecked, isLoggedIn, router]); +const formSchema = z.object({ + user_id: z.string(), + password: z.string() +}) - const handleChange = (fieldType: 'username' | 'password') => (e: any) => { - const setField = fieldType === 'username' ? setUsername : setPassword; - setField(e.target.value); - setError(''); - }; +const Login = () => { + const form = useForm>({ + resolver: zodResolver(formSchema), + defaultValues: { + user_id: '', + password: '' + }, + }) - const handleSubmit: React.FormEventHandler = async (e) => { - e.preventDefault(); + const onSubmit = async (values: z.infer) => { try { - const r = await login(username, password); - console.log(r); - const success = getClientCookie('tokenDrinking'); - if (success) { - console.log('Logged in'); - router.push('/user/template/home'); - } - } catch (e) { - setError('En feil oppsto under innloggingen.'); - } - }; + + } catch (error) { - if (!authChecked) { - return ; + } } return ( -
-
-

- Logg inn til Blitzed -

-
- - -
- Samme som Tihlde bruker -
- - - - - Glemt passord? - - {error && ( - - )} -
-
+
+ + + + + + + +
+ + ( + + + Brukernavn + + + + + + )} + /> + + ( + + + Passord + + + + + + )} + /> + + + + +
+
); -} +}; + + +export default Login; diff --git a/components/layout/navbar.tsx b/components/layout/navbar.tsx index ba3b8b7..1494946 100644 --- a/components/layout/navbar.tsx +++ b/components/layout/navbar.tsx @@ -31,12 +31,12 @@ export default function Navbar() { */}