diff --git a/frontend/app/login/page.tsx b/frontend/app/login/page.tsx index 54f1c6b7..c7aa4772 100644 --- a/frontend/app/login/page.tsx +++ b/frontend/app/login/page.tsx @@ -1,14 +1,103 @@ 'use client'; -import { useState, FormEvent } from 'react'; +import { useState, FormEvent, Suspense } from 'react'; import { signIn } from 'next-auth/react'; import { useRouter, useSearchParams } from 'next/navigation'; -export default function LoginPage() { +function LoginForm() { const router = useRouter(); const searchParams = useSearchParams(); const callbackUrl = searchParams?.get('callbackUrl') ?? '/'; + const [username, setUsername] = useState(''); + const [password, setPassword] = useState(''); + const [error, setError] = useState(''); + const [loading, setLoading] = useState(false); + + async function handleSubmit(e: FormEvent) { + e.preventDefault(); + setError(''); + setLoading(true); + const result = await signIn('credentials', { + username, + password, + redirect: false, + }); + setLoading(false); + if (result?.error) { + setError('Felaktigt användarnamn eller lösenord'); + } else { + router.push(callbackUrl); + router.refresh(); + } + } + + return ( +
+ ); +} + +export default function LoginPage() { + return ( +