2024-09-12 17:36:58 -05:00

28 lines
833 B
TypeScript

import { NextResponse } from 'next/server';
import { updateUserPushToken } from '~/server/functions';
type Data = {
apiKey: string;
userId: string;
pushToken: string;
};
export const POST = async (request: Request) => {
try {
const { apiKey, userId, pushToken } = await request.json() as Data;
// Validate API key (optional, but since you do it, let's continue)
if (apiKey !== process.env.API_KEY) {
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
}
// Update push token in the database
await updateUserPushToken(parseInt(userId), pushToken);
return NextResponse.json({ message: "Push token updated successfully" });
} catch (error) {
console.error(error);
return NextResponse.json({ message: "Error updating push token" }, { status: 500 });
}
};