24 lines
719 B
TypeScript
24 lines
719 B
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { auth } from '@/lib/auth'
|
|
import { prisma } from '@innungsapp/shared'
|
|
|
|
export async function POST(req: NextRequest) {
|
|
const session = await auth.api.getSession({ headers: req.headers })
|
|
if (!session?.user) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
}
|
|
|
|
const { token } = await req.json()
|
|
if (!token || typeof token !== 'string') {
|
|
return NextResponse.json({ error: 'Invalid token' }, { status: 400 })
|
|
}
|
|
|
|
// Store push token on the member record
|
|
await prisma.member.updateMany({
|
|
where: { userId: session.user.id },
|
|
data: { pushToken: token },
|
|
})
|
|
|
|
return NextResponse.json({ success: true })
|
|
}
|