feat: gebruikersprofiel met avatar, bio en uitgebreide beschrijving
- Schema: bio (160), bio_detail (2000) en avatar_data (bytea) op User - POST /api/profile/avatar: validatie MIME-type + max 12 MB vóór verwerking, Sharp resize naar max 700x700 (fit inside), output WebP q85, opgeslagen als bytea in Neon - GET /api/profile/avatar: serveert avatar met Cache-Control private 1u - updateProfileAction: slaat bio en bio_detail op via Server Action + Zod - ProfileEditor client component: avatar preview, upload met client-side validatie, bio-velden met tekenlimieten - Settings page: profiel-sectie bovenaan, uitgeschakeld voor demo-gebruiker - next.config: sharp als serverExternalPackage Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
45011a3347
commit
1ff894a6c0
7 changed files with 300 additions and 1 deletions
40
actions/profile.ts
Normal file
40
actions/profile.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
'use server'
|
||||
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { cookies } from 'next/headers'
|
||||
import { getIronSession } from 'iron-session'
|
||||
import { z } from 'zod'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import { SessionData, sessionOptions } from '@/lib/session'
|
||||
|
||||
async function getSession() {
|
||||
return getIronSession<SessionData>(await cookies(), sessionOptions)
|
||||
}
|
||||
|
||||
const profileSchema = z.object({
|
||||
bio: z.string().max(160).optional(),
|
||||
bio_detail: z.string().max(2000).optional(),
|
||||
})
|
||||
|
||||
export async function updateProfileAction(_prevState: unknown, formData: FormData) {
|
||||
const session = await getSession()
|
||||
if (!session.userId) return { error: 'Niet ingelogd' }
|
||||
if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' }
|
||||
|
||||
const parsed = profileSchema.safeParse({
|
||||
bio: (formData.get('bio') as string) || undefined,
|
||||
bio_detail: (formData.get('bio_detail') as string) || undefined,
|
||||
})
|
||||
if (!parsed.success) return { error: parsed.error.flatten().fieldErrors }
|
||||
|
||||
await prisma.user.update({
|
||||
where: { id: session.userId },
|
||||
data: {
|
||||
bio: parsed.data.bio ?? null,
|
||||
bio_detail: parsed.data.bio_detail ?? null,
|
||||
},
|
||||
})
|
||||
|
||||
revalidatePath('/settings')
|
||||
return { success: true }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue