feat(auth): better-auth mit passwort, passkeys und app-shell
Registrierung des ersten Nutzers macht ihn zum Administrator, danach ist die Registrierung geschlossen (Einladungen folgen in Phase 2). Login per Passwort oder Passkey inklusive Conditional UI, Verwaltung der Passkeys unter "Konto" mit Umbenennen und Loeschen. Rate-Limiting liegt in der Datenbank und ueberlebt Neustarts; Session-Cookies sind httpOnly, sameSite=lax und im Produktivbetrieb secure. Die Client-IP wird hinter dem Reverse Proxy aus x-forwarded-for gelesen. Dazu die mobile-first Grundstruktur: Bottom-Navigation, Header mit Konto-Menue, Healthcheck unter /api/health und ein Dashboard mit den vier Einstiegspunkten. Bedienelemente sind auf 44px Touch-Groesse angehoben. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { getSessionCookie } from 'better-auth/cookies';
|
||||
import { NextResponse, type NextRequest } from 'next/server';
|
||||
|
||||
/**
|
||||
* Optimistic route guard: it only checks whether a session cookie is present,
|
||||
* which keeps the middleware free of database access. The real check happens
|
||||
* in every page and server action via `requireUser()`.
|
||||
*/
|
||||
export function middleware(request: NextRequest) {
|
||||
const hasSession = getSessionCookie(request, { cookiePrefix: 'bricktrack' });
|
||||
if (hasSession) return NextResponse.next();
|
||||
|
||||
const target = new URL('/anmelden', request.url);
|
||||
const { pathname, search } = request.nextUrl;
|
||||
if (pathname !== '/') {
|
||||
target.searchParams.set('weiter', `${pathname}${search}`);
|
||||
}
|
||||
return NextResponse.redirect(target);
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: [
|
||||
/*
|
||||
* Everything except the public surface:
|
||||
* - /anmelden, /registrieren, /einladung (auth pages)
|
||||
* - /w/... (public wishlists)
|
||||
* - /api/auth, /api/health, /api/files (handled by their own guards)
|
||||
* - Next internals and static assets
|
||||
*/
|
||||
'/((?!anmelden|registrieren|einladung|w/|api/auth|api/health|api/files|_next/static|_next/image|favicon.ico|icons/|manifest.webmanifest).*)',
|
||||
],
|
||||
};
|
||||
Reference in New Issue
Block a user