memento-mobile/ (Expo + React Native + expo-router): - Auth: login email/password → Bearer token (expo-secure-store) - Layout: guard auth → redirect /(auth)/login ou /(tabs)/home - Tabs: Accueil, Carnets, Recherche, Profil - Screens: login, home (recent notes + quick actions), notebooks list, note viewer (WebView HTML), search (texte), notebook detail, profile - Design: tokens brand-accent (#A47148), ink, concrete, paper, border - lib/config.ts: API_URL dev/prod configurable - lib/api.ts: apiFetch avec Bearer token automatique - lib/store.ts: Zustand auth store (login/logout/restore) memento-note/ (API mobile dédiée): - lib/mobile-auth.ts: createMobileToken / verifyMobileToken (HMAC-SHA256, 90j) - POST /api/mobile/auth/login: email+password → token + user - GET /api/mobile/auth/me: valider token, retourner profil - GET /api/mobile/notebooks: liste carnets avec nb notes - GET /api/mobile/notes: notes récentes (filtre par carnet optionnel) - GET /api/mobile/notes/[id]: contenu complet d'une note - GET /api/mobile/search: recherche fulltext titre+contenu Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import prisma from '@/lib/prisma'
|
|
import bcrypt from 'bcryptjs'
|
|
import { createMobileToken } from '@/lib/mobile-auth'
|
|
|
|
export async function POST(req: NextRequest) {
|
|
try {
|
|
const { email, password } = await req.json()
|
|
if (!email || !password) {
|
|
return NextResponse.json({ error: 'Email et mot de passe requis' }, { status: 400 })
|
|
}
|
|
|
|
const user = await prisma.user.findUnique({
|
|
where: { email: email.toLowerCase().trim() },
|
|
select: {
|
|
id: true, name: true, email: true, password: true,
|
|
subscription: { select: { tier: true } },
|
|
},
|
|
})
|
|
|
|
if (!user?.password) {
|
|
return NextResponse.json({ error: 'Identifiants invalides' }, { status: 401 })
|
|
}
|
|
|
|
const valid = await bcrypt.compare(password, user.password)
|
|
if (!valid) {
|
|
return NextResponse.json({ error: 'Identifiants invalides' }, { status: 401 })
|
|
}
|
|
|
|
const token = createMobileToken(user.id)
|
|
return NextResponse.json({
|
|
token,
|
|
user: {
|
|
id: user.id,
|
|
name: user.name,
|
|
email: user.email,
|
|
tier: user.subscription?.tier ?? 'FREE',
|
|
},
|
|
})
|
|
} catch (e) {
|
|
console.error('[mobile/auth/login]', e)
|
|
return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 })
|
|
}
|
|
}
|
|
|