Initial commit
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import { useState } from 'react'
|
||||
import { useAuth } from '@/context/AuthContext'
|
||||
|
||||
export function Auth() {
|
||||
const { login, register } = useAuth()
|
||||
const [isRegister, setIsRegister] = useState(false)
|
||||
const [email, setEmail] = useState('')
|
||||
const [password, setPassword] = useState('')
|
||||
const [displayName, setDisplayName] = useState('')
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
setError(null)
|
||||
try {
|
||||
if (isRegister) {
|
||||
await register({ email, password, displayName })
|
||||
} else {
|
||||
await login({ email, password })
|
||||
}
|
||||
} catch (err: unknown) {
|
||||
setError(err instanceof Error ? err.message : 'Något gick fel')
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<main>
|
||||
<h1>{isRegister ? 'Skapa konto' : 'Logga in'}</h1>
|
||||
<form onSubmit={(e) => void handleSubmit(e)}>
|
||||
{isRegister && (
|
||||
<input
|
||||
placeholder="Namn"
|
||||
value={displayName}
|
||||
onChange={(e) => setDisplayName(e.target.value)}
|
||||
/>
|
||||
)}
|
||||
<input
|
||||
type="email"
|
||||
placeholder="E-post"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
/>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Lösenord"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
/>
|
||||
{error && <p role="alert">{error}</p>}
|
||||
<button type="submit">{isRegister ? 'Registrera' : 'Logga in'}</button>
|
||||
</form>
|
||||
<button type="button" onClick={() => setIsRegister((v) => !v)}>
|
||||
{isRegister ? 'Har redan konto' : 'Skapa konto'}
|
||||
</button>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export function Calendar() {
|
||||
return <main><h1>Kalender</h1></main>
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export function Dashboard() {
|
||||
return <main><h1>Översikt</h1></main>
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export function Settings() {
|
||||
return <main><h1>Inställningar</h1></main>
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export function Tips() {
|
||||
return <main><h1>Tips</h1></main>
|
||||
}
|
||||
Reference in New Issue
Block a user