Add push notif support
This commit is contained in:
@ -20,4 +20,4 @@ export const POST = async (request: NextRequest) => {
|
||||
return NextResponse.json({ message: "Error" }, { status: 500 });
|
||||
}
|
||||
};
|
||||
// localhost:3000/api/setCountdown?apiKey=I_Love_Madeline&countdown=2023-01-01T00:00:00.000Z
|
||||
// localhost:3000/api/setCountdown?apiKey=I_Love_Madeline&countdown=2024-09-20T12:00:00.000Z
|
||||
|
27
src/app/api/updatePushToken/route.ts
Normal file
27
src/app/api/updatePushToken/route.ts
Normal file
@ -0,0 +1,27 @@
|
||||
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 });
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user