Skip to content

Commit

Permalink
fix: logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Joabesv committed Feb 11, 2025
1 parent 8c27c31 commit 333172c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions app/api/facebook/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@ const app = require("@/app");
module.exports = async (context) => {
const { ra, email } = context.body;

const user = await app.models.users.findOne({
ra,
$or: [{ "oauth.facebookEmail": email }, { "oauth.email": email }],
});
// Find user by RA first
const user = await app.models.users.findOne({ ra, 'oauth.facebook': { $exists: true } });

if (!user) {
throw new Error("User does not exists");
throw new Error('User does not exist');
}

const userEmails = [
user.oauth?.emailFacebook,
user.oauth?.email,
].filter(Boolean);

if (!userEmails.includes(email)) {
throw new Error('Email does not match the registered email for this RA');
}

// Generate JWT token only if email matches
return {
token: user.generateJWT(),
token: user.generateJWT()
};
};

0 comments on commit 333172c

Please sign in to comment.