Trying to fix push notifs
This commit is contained in:
		@@ -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 });
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -14,7 +14,7 @@ export const users = createTable(
 | 
			
		||||
    id: serial("id").primaryKey(),
 | 
			
		||||
    name: varchar("name", { length: 256 }),
 | 
			
		||||
    message: varchar("message", { length: 256 }),
 | 
			
		||||
    pushToken: varchar("push_token", { length: 256 }),
 | 
			
		||||
    pushToken: varchar("pushToken", { length: 256 }),
 | 
			
		||||
    createdAt: timestamp("created_at", { withTimezone: true })
 | 
			
		||||
      .default(sql`CURRENT_TIMESTAMP`)
 | 
			
		||||
      .notNull(),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user