Trying to fix push notifs

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

View File

@ -12,7 +12,7 @@
"dev": "next dev", "dev": "next dev",
"lint": "next lint", "lint": "next lint",
"start": "next start", "start": "next start",
"go": "next build && next start" "go": "git pull docker master && next build && next start"
}, },
"dependencies": { "dependencies": {
"@t3-oss/env-nextjs": "^0.10.1", "@t3-oss/env-nextjs": "^0.10.1",

View File

@ -10,18 +10,20 @@ type Data = {
export const POST = async (request: Request) => { export const POST = async (request: Request) => {
try { try {
const { apiKey, userId, pushToken } = await request.json() as Data; 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) { if (apiKey !== process.env.API_KEY) {
console.log('Invalid API Key');
return NextResponse.json({ message: "Invalid API Key" }, { status: 401 }); 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); await updateUserPushToken(parseInt(userId), pushToken);
console.log('Push token updated successfully');
return NextResponse.json({ message: "Push token updated successfully" }); return NextResponse.json({ message: "Push token updated successfully" });
} catch (error) { } catch (error) {
console.error(error); console.error('Error in updatePushToken:', error);
return NextResponse.json({ message: "Error updating push token" }, { status: 500 }); return NextResponse.json({ message: "Error updating push token" }, { status: 500 });
} }
}; };

View File

@ -14,7 +14,7 @@ export const users = createTable(
id: serial("id").primaryKey(), id: serial("id").primaryKey(),
name: varchar("name", { length: 256 }), name: varchar("name", { length: 256 }),
message: varchar("message", { length: 256 }), message: varchar("message", { length: 256 }),
pushToken: varchar("push_token", { length: 256 }), pushToken: varchar("pushToken", { length: 256 }),
createdAt: timestamp("created_at", { withTimezone: true }) createdAt: timestamp("created_at", { withTimezone: true })
.default(sql`CURRENT_TIMESTAMP`) .default(sql`CURRENT_TIMESTAMP`)
.notNull(), .notNull(),