Add authentication system with next-auth (CredentialsProvider + JWT)

- Login page with email/password
- Auth middleware (proxy) protecting all routes
- Seed endpoint for admin user creation (admin@optiquestock.com / admin123)
- Session provider wrapping root layout
- User info + logout button in header
- Updated POS sales route to track authenticated user
This commit is contained in:
2026-05-30 15:35:40 +01:00
parent d23f2ab53e
commit 816c1c40c6
13 changed files with 291 additions and 25 deletions

View File

@@ -1,6 +1,8 @@
'use client'
import { useState } from 'react'
import { useSession, signOut } from 'next-auth/react'
import { useRouter } from 'next/navigation'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
import { Button } from '@/components/ui/button'
import { Badge } from '@/components/ui/badge'
@@ -13,7 +15,9 @@ import {
BarChart3,
Eye,
LayoutDashboard,
Wrench
Wrench,
LogOut,
User
} from 'lucide-react'
import POSModule from '@/components/pos/POSModule'
import { ProduitListe } from '@/components/products/ProduitListe'
@@ -90,8 +94,15 @@ const modules: ModuleCard[] = [
]
export default function Home() {
const { data: session } = useSession()
const router = useRouter()
const [currentModule, setCurrentModule] = useState<Module>('HOME')
if (!session) {
router.push('/login')
return null
}
const renderModule = () => {
if (currentModule === 'HOME') {
return (
@@ -347,9 +358,18 @@ export default function Home() {
<Badge variant="outline" className="text-sm">
v1.0.0
</Badge>
<div className="h-8 w-8 rounded-full bg-primary flex items-center justify-center text-primary-foreground text-sm font-medium">
OP
<div className="flex items-center gap-2 text-sm text-gray-600">
<User className="h-4 w-4" />
<span className="hidden sm:inline">{session?.user?.name}</span>
</div>
<Button
variant="ghost"
size="icon"
onClick={() => signOut({ callbackUrl: '/login' })}
title="Se déconnecter"
>
<LogOut className="h-4 w-4" />
</Button>
</div>
</div>
</div>