Trying to fix push notifs

This commit is contained in:
2024-09-25 10:26:00 -05:00
parent 03fc9c9c1e
commit dcc57a43bb
3 changed files with 7 additions and 5 deletions

View File

@@ -10,18 +10,20 @@ type Data = {
export const POST = async (request: Request) => {
try {
const { apiKey, userId, pushToken } = await request.json() as Data;
console.log('Received request:', { apiKey, userId, pushToken });
// Validate API key (optional, but since you do it, let's continue)
if (apiKey !== process.env.API_KEY) {
console.log('Invalid API Key');
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 });
}
// Update push token in the database
console.log('Updating push token for user:', userId);
await updateUserPushToken(parseInt(userId), pushToken);
console.log('Push token updated successfully');
return NextResponse.json({ message: "Push token updated successfully" });
} catch (error) {
console.error(error);
console.error('Error in updatePushToken:', error);
return NextResponse.json({ message: "Error updating push token" }, { status: 500 });
}
};