MVP frontend+backend

This commit is contained in:
2026-06-14 09:58:30 +02:00
parent d9539f23cc
commit 772d853e37
56 changed files with 5099 additions and 207 deletions
+14 -2
View File
@@ -1,22 +1,34 @@
import { useState } from 'react'
import { useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { useAuth } from '@/context/AuthContext'
import { useWorkspace } from '@/context/WorkspaceContext'
export function Auth() {
const { login, register } = useAuth()
const { login, register, isAuthenticated } = useAuth()
const { isLoading: wsLoading } = useWorkspace()
const navigate = useNavigate()
const [isRegister, setIsRegister] = useState(false)
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const [displayName, setDisplayName] = useState('')
const [error, setError] = useState<string | null>(null)
useEffect(() => {
if (isAuthenticated && !wsLoading) {
navigate('/', { replace: true })
}
}, [isAuthenticated, wsLoading, navigate])
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()
setError(null)
try {
if (isRegister) {
await register({ email, password, displayName })
navigate('/', { replace: true })
} else {
await login({ email, password })
navigate('/', { replace: true })
}
} catch (err: unknown) {
setError(err instanceof Error ? err.message : 'Något gick fel')