Skip to content

Commit

Permalink
Fix username not saving bug
Browse files Browse the repository at this point in the history
  • Loading branch information
codergautam committed Dec 19, 2024
1 parent ac80cb6 commit 09c2f8e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/googleAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ export default async function handler(req, res) {
}).select("secret username email staff canMakeClues supporter").cache(120);
if (userDb) {
output = { secret: userDb.secret, username: userDb.username, email: userDb.email, staff: userDb.staff, canMakeClues: userDb.canMakeClues, supporter: userDb.supporter };
if(!userDb.username || userDb.username.length < 1) {
// try again without cache, to prevent new users getting stuck with no username
const userDb2 = await User.findOne({
secret,
}).select("secret username email staff canMakeClues supporter");
if(userDb2) output = { secret: userDb2.secret, username: userDb2.username, email: userDb2.email, staff: userDb2.staff, canMakeClues: userDb2.canMakeClues, supporter: userDb2.supporter };
}

return res.status(200).json(output);
} else {
return res.status(400).json({ error: 'Invalid' });
Expand Down

0 comments on commit 09c2f8e

Please sign in to comment.