diff --git a/.gitignore b/.gitignore index 457ba4c..c4ea55a 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ tsconfig.tsbuildinfo openai.key docs.tgz CACHEDIR.TAG +docs/drawio/.cache/ diff --git a/app/api/auth/me/route.ts b/app/api/auth/me/route.ts index a2816bc..3cfef54 100644 --- a/app/api/auth/me/route.ts +++ b/app/api/auth/me/route.ts @@ -7,7 +7,7 @@ export async function GET(req: Request) { const session = await requireAuth(req); const user = await prisma.user.findUnique({ where: { id: session.userId }, - select: { id: true, email: true, role: true, status: true, emailVerifiedAt: true, approvedAt: true, name: true }, + select: { id: true, email: true, role: true, status: true, emailVerifiedAt: true, approvedAt: true, name: true, phone: true }, }); if (!user) return NextResponse.json({ error: 'Not found' }, { status: 404 }); return NextResponse.json({ user }); diff --git a/app/api/me/route.ts b/app/api/me/route.ts index 8fddd36..4adaa5d 100644 --- a/app/api/me/route.ts +++ b/app/api/me/route.ts @@ -9,14 +9,16 @@ export async function PATCH(req: Request) { const body = await req.json(); const name = body.name !== undefined && body.name !== null ? String(body.name).trim() : undefined; + const phone = body.phone !== undefined && body.phone !== null ? String(body.phone).trim() : undefined; const password = body.password ? String(body.password) : undefined; - if (name === undefined && !password) { + if (name === undefined && phone === undefined && !password) { return NextResponse.json({ error: 'No updates provided' }, { status: 400 }); } const data: any = {}; if (name !== undefined) data.name = name || null; + if (phone !== undefined) data.phone = phone || null; if (password) { if (password.length < 8) { return NextResponse.json({ error: 'Password must be at least 8 characters' }, { status: 400 }); @@ -27,7 +29,7 @@ export async function PATCH(req: Request) { const user = await prisma.user.update({ where: { id: session.userId }, data, - select: { id: true, email: true, name: true, role: true, status: true, emailVerifiedAt: true, approvedAt: true }, + select: { id: true, email: true, name: true, phone: true, role: true, status: true, emailVerifiedAt: true, approvedAt: true }, }); return NextResponse.json({ ok: true, user }); diff --git a/app/me/page.tsx b/app/me/page.tsx index 606f118..ee65f51 100644 --- a/app/me/page.tsx +++ b/app/me/page.tsx @@ -3,13 +3,14 @@ import { useEffect, useState } from 'react'; import { useI18n } from '../components/I18nProvider'; -type User = { id: string; email: string; role: string; status: string; emailVerifiedAt: string | null; approvedAt: string | null; name: string | null }; +type User = { id: string; email: string; role: string; status: string; emailVerifiedAt: string | null; approvedAt: string | null; name: string | null; phone: string | null }; export default function ProfilePage() { const { t } = useI18n(); const [user, setUser] = useState(null); const [error, setError] = useState(null); const [name, setName] = useState(''); + const [phone, setPhone] = useState(''); const [password, setPassword] = useState(''); const [saving, setSaving] = useState(false); const [message, setMessage] = useState(null); @@ -21,6 +22,7 @@ export default function ProfilePage() { if (data.user) { setUser(data.user); setName(data.user.name ?? ''); + setPhone(data.user.phone ?? ''); } else setError(t('notLoggedIn')); }) .catch(() => setError(t('notLoggedIn'))); @@ -35,7 +37,7 @@ export default function ProfilePage() { const res = await fetch('/api/me', { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ name, password: password || undefined }), + body: JSON.stringify({ name, phone, password: password || undefined }), }); const data = await res.json(); if (!res.ok) { @@ -65,6 +67,9 @@ export default function ProfilePage() {
  • {t('profileName')}: {user.name ?? '—'}
  • +
  • + {t('profilePhone')}: {user.phone ?? '—'} +
  • {t('profileRole')}: {user.role}
  • @@ -91,6 +96,10 @@ export default function ProfilePage() { {t('profileName')} setName(e.target.value)} /> +