Skip to content

Commit ca3cac0

Browse files
committed
fix
1 parent 7223d34 commit ca3cac0

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

api/users/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export default async function handler(
9191
},
9292
};
9393

94-
const result = await usersCollection.findOneAndUpdate(
94+
const result = await usersCollection.updateOne(
9595
{ firebaseUid },
9696
{
9797
$setOnInsert: defaults,
@@ -102,18 +102,19 @@ export default async function handler(
102102
lastLoginAt: now,
103103
},
104104
},
105-
{ upsert: true, returnDocument: "after" },
105+
{ upsert: true },
106106
);
107107

108-
if (!result.value) {
108+
const user = await usersCollection.findOne({ firebaseUid });
109+
if (!user) {
109110
throw new Error("Failed to create or fetch user");
110111
}
111112

112-
const wasExisting = Boolean(result.lastErrorObject?.updatedExisting);
113+
const wasExisting = result.upsertedCount === 0;
113114

114115
return res.status(wasExisting ? 200 : 201).json({
115116
success: true,
116-
user: result.value,
117+
user,
117118
});
118119
} catch (error) {
119120
console.error("Error creating user:", error);

0 commit comments

Comments
 (0)