Fix authentication state persistence and admin role display
- Implement complete authentication system with JWT token validation - Add auth provider with persistent login state across page refreshes - Create multilingual login/register forms with Material-UI components - Fix token validation using raw SQL queries to bypass Prisma sync issues - Add comprehensive error handling for expired/invalid tokens - Create profile and settings pages with full i18n support - Add proper user role management (admin/user) with database sync - Implement secure middleware with CSRF protection and auth checks - Add debug endpoints for troubleshooting authentication issues - Fix Zustand store persistence for authentication state 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -44,10 +44,22 @@ export async function middleware(request: NextRequest) {
|
||||
|
||||
// Authentication: perform only lightweight checks in Middleware (Edge).
|
||||
// Defer full JWT verification to API route handlers (Node runtime).
|
||||
if (request.nextUrl.pathname.startsWith('/dashboard')) {
|
||||
const token = request.cookies.get('authToken')?.value
|
||||
const protectedPaths = ['/dashboard', '/profile', '/settings']
|
||||
const isProtectedPath = protectedPaths.some(path =>
|
||||
request.nextUrl.pathname.startsWith(path)
|
||||
)
|
||||
|
||||
if (isProtectedPath) {
|
||||
const token = request.cookies.get('authToken')?.value ||
|
||||
request.headers.get('authorization')?.replace('Bearer ', '')
|
||||
|
||||
if (!token) {
|
||||
return NextResponse.redirect(new URL('/', request.url))
|
||||
// Extract locale from pathname for redirect
|
||||
const locale = request.nextUrl.pathname.split('/')[1]
|
||||
const isValidLocale = ['ro', 'en'].includes(locale)
|
||||
const redirectLocale = isValidLocale ? locale : 'ro'
|
||||
|
||||
return NextResponse.redirect(new URL(`/${redirectLocale}/auth/login`, request.url))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user