This commit is contained in:
Timo Knuth
2026-02-27 15:19:24 +01:00
parent b7f8221095
commit 253c3c1c6d
134 changed files with 11188 additions and 1871 deletions

View File

@@ -1,180 +1,106 @@
'use client'
import Link from 'next/link'
import { getTenantSlug } from '@/lib/tenant'
import { prisma } from '@innungsapp/shared'
import { LoginForm } from '@/components/auth/LoginForm'
import { useState } from 'react'
import { createAuthClient } from 'better-auth/react'
import { magicLinkClient } from 'better-auth/client/plugins'
const authClient = createAuthClient({
plugins: [magicLinkClient()],
})
export default async function LoginPage() {
const slug = await getTenantSlug()
type Mode = 'password' | 'magic'
export default function LoginPage() {
const [mode, setMode] = useState<Mode>('password')
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const [sent, setSent] = useState(false)
const [loading, setLoading] = useState(false)
const [error, setError] = useState('')
async function handleSubmit(e: React.FormEvent) {
e.preventDefault()
setLoading(true)
setError('')
if (mode === 'password') {
const result = await authClient.signIn.email({
email,
password,
callbackURL: '/dashboard',
})
setLoading(false)
if (result.error) {
setError(result.error.message ?? 'E-Mail oder Passwort falsch.')
} else {
window.location.href = '/dashboard'
}
} else {
const result = await authClient.signIn.magicLink({
email,
callbackURL: '/dashboard',
})
setLoading(false)
if (result.error) {
setError(result.error.message ?? 'Ein Fehler ist aufgetreten.')
} else {
setSent(true)
}
}
let org = null
if (slug) {
org = await prisma.organization.findUnique({
where: { slug }
})
}
const primaryColor = org?.primaryColor || '#E63946'
const orgName = org?.name || 'InnungsApp'
const logoUrl = org?.logoUrl || '/logo.png'
const secondaryText = org ? `Verwaltungsportal für die ${org.name}` : 'Verwaltungsportal für Innungen'
return (
<div className="min-h-screen bg-gray-50 flex items-center justify-center p-4">
<div className="w-full max-w-sm">
{/* Logo */}
<div className="text-center mb-8">
<h1
className="text-3xl font-bold text-gray-900 tracking-tight"
style={{ fontFamily: "'Syne', system-ui, sans-serif" }}
>
Innungs<span className="text-brand-500">App</span>
</h1>
<p className="text-sm text-gray-500 mt-1">Verwaltungsportal für Innungen</p>
</div>
<div className="bg-white rounded-lg border p-8">
{sent ? (
<div className="text-center py-4">
<div className="w-14 h-14 bg-green-50 border border-green-100 rounded-full flex items-center justify-center mx-auto mb-4">
<svg className="w-7 h-7 text-green-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5} d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />
</svg>
</div>
<h2 className="text-lg font-semibold text-gray-900 mb-2">E-Mail gesendet</h2>
<p className="text-sm text-gray-500">
Login-Link an <strong className="text-gray-700">{email}</strong> gesendet. Bitte prüfen Sie Ihr Postfach.
</p>
<button
onClick={() => setSent(false)}
className="mt-6 text-brand-600 text-sm hover:underline"
<div className="min-h-screen bg-gray-50 flex flex-col">
<main className="flex-1 flex items-center justify-center p-4">
<div className="w-full max-w-sm">
<div className="mb-4">
<Link
href={slug ? `/${slug}` : "/"}
aria-label="Zur Startseite"
className="inline-flex h-10 w-10 items-center justify-center rounded-lg border border-gray-200 bg-white text-gray-600 shadow-sm transition-colors hover:text-gray-900 hover:border-gray-300"
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
className="h-5 w-5"
aria-hidden="true"
>
Andere E-Mail verwenden
</button>
<path d="M3 11.5 12 4l9 7.5" />
<path d="M5.5 10.5V20h13V10.5" />
<path d="M10 20v-5h4v5" />
</svg>
</Link>
</div>
<div className="text-center mb-8">
<div className="mx-auto mb-4 flex h-14 w-14 items-center justify-center rounded-full bg-white shadow-md border border-gray-100 overflow-hidden">
<img
src={logoUrl}
alt={orgName}
className={`h-10 w-10 object-contain ${!org?.logoUrl ? 'brightness-110 scale-[1.6]' : ''}`}
/>
</div>
) : (
<>
<h2
className="text-lg font-semibold text-gray-900 mb-5"
style={{ fontFamily: "'Syne', system-ui, sans-serif" }}
>
Anmelden
</h2>
{/* Mode toggle */}
<div className="flex rounded-lg border border-gray-200 p-0.5 mb-5 bg-gray-50">
<button
type="button"
onClick={() => setMode('password')}
className={`flex-1 py-1.5 text-sm rounded-md font-medium transition-all ${
mode === 'password'
? 'bg-white shadow-sm text-gray-900 border border-gray-200'
: 'text-gray-500 hover:text-gray-700'
}`}
>
Passwort
</button>
<button
type="button"
onClick={() => setMode('magic')}
className={`flex-1 py-1.5 text-sm rounded-md font-medium transition-all ${
mode === 'magic'
? 'bg-white shadow-sm text-gray-900 border border-gray-200'
: 'text-gray-500 hover:text-gray-700'
}`}
>
Magic Link
</button>
</div>
<form onSubmit={handleSubmit} className="space-y-4">
<div>
<label htmlFor="email" className="block text-xs font-medium text-gray-600 mb-1 uppercase tracking-wide">
E-Mail-Adresse
</label>
<input
id="email"
type="email"
required
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="admin@ihre-innung.de"
className="w-full px-3 py-2.5 border border-gray-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-brand-500 focus:border-transparent"
/>
</div>
{mode === 'password' && (
<div>
<label htmlFor="password" className="block text-xs font-medium text-gray-600 mb-1 uppercase tracking-wide">
Passwort
</label>
<input
id="password"
type="password"
required
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="••••••••"
className="w-full px-3 py-2.5 border border-gray-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-brand-500 focus:border-transparent"
/>
</div>
)}
{error && (
<p className="text-sm text-red-600 bg-red-50 px-3 py-2 rounded-lg">{error}</p>
)}
<button
type="submit"
disabled={loading}
className="w-full bg-brand-500 text-white py-2.5 px-4 rounded-lg text-sm font-medium hover:bg-brand-600 disabled:opacity-60 disabled:cursor-not-allowed transition-colors"
>
{loading
? 'Bitte warten...'
: mode === 'password'
? 'Anmelden'
: 'Magic Link senden'}
</button>
</form>
{mode === 'password' && (
<p className="mt-4 text-center text-xs text-gray-400">
Demo: admin@demo.de / demo1234
</p>
<h1
className="text-3xl font-bold text-gray-900 tracking-tight"
style={{ fontFamily: "'Syne', system-ui, sans-serif" }}
>
{org ? (
<>
<span style={{ color: primaryColor }}>{org.name.split(' ')[0]}</span>
{org.name.includes(' ') ? ` ${org.name.split(' ').slice(1).join(' ')}` : ''}
</>
) : (
<>
Innungs<span className="text-brand-500">App</span>
</>
)}
</>
)}
</h1>
<p className="text-sm text-gray-500 mt-1">{secondaryText}</p>
</div>
<div className="bg-white rounded-lg border p-8">
<h2
className="text-lg font-semibold text-gray-900 mb-5"
style={{ fontFamily: "'Syne', system-ui, sans-serif" }}
>
Anmelden
</h2>
<LoginForm primaryColor={primaryColor} />
</div>
</div>
</div>
</main>
<footer className="border-t border-gray-200 bg-white/80 backdrop-blur">
<div className="max-w-4xl mx-auto px-4 py-4 flex flex-wrap items-center justify-between gap-3 text-xs text-gray-500">
<p>(c) {new Date().getFullYear()} InnungsApp</p>
<div className="flex items-center gap-4">
<Link href={slug ? `/${slug}` : "/"} className="hover:text-gray-700">
Home
</Link>
<Link href="/impressum" className="hover:text-gray-700">
Impressum
</Link>
<Link href="/datenschutz" className="hover:text-gray-700">
Datenschutz
</Link>
</div>
</div>
</footer>
</div>
)
}