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:
andupetcu
2025-09-21 01:06:30 +03:00
parent 62ca73b2ac
commit 196ca00194
174 changed files with 181207 additions and 179 deletions

View File

@@ -3,23 +3,46 @@ import { getUserFromToken } from '@/lib/auth'
export const runtime = 'nodejs'
function getErrorMessages(locale: string = 'ro') {
const messages = {
ro: {
tokenRequired: 'Token de autentificare necesar',
invalidToken: 'Token invalid',
serverError: 'Eroare de server'
},
en: {
tokenRequired: 'Authentication token required',
invalidToken: 'Invalid token',
serverError: 'Server error'
}
}
return messages[locale as keyof typeof messages] || messages.ro
}
export async function GET(request: Request) {
try {
const url = new URL(request.url)
const locale = url.searchParams.get('locale') || 'ro'
const messages = getErrorMessages(locale)
const authHeader = request.headers.get('authorization')
const token = authHeader?.replace('Bearer ', '')
if (!token) {
return NextResponse.json({ error: 'Token de autentificare necesar' }, { status: 401 })
return NextResponse.json({ error: messages.tokenRequired }, { status: 401 })
}
const user = await getUserFromToken(token)
if (!user) {
return NextResponse.json({ error: 'Token invalid' }, { status: 401 })
return NextResponse.json({ error: messages.invalidToken }, { status: 401 })
}
return NextResponse.json({ user })
} catch (error) {
console.error('User validation error:', error)
return NextResponse.json({ error: 'Eroare de server' }, { status: 500 })
const url = new URL(request.url)
const locale = url.searchParams.get('locale') || 'ro'
const messages = getErrorMessages(locale)
return NextResponse.json({ error: messages.serverError }, { status: 500 })
}
}