Skip to content

Commit

Permalink
Merge pull request #171 from ufabc-next/fix/facebook-login
Browse files Browse the repository at this point in the history
Fix/facebook login
  • Loading branch information
brMonteiro-G authored Feb 11, 2025
2 parents 8c27c31 + 859b443 commit 80e3efb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/agenda/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const DEFAULT_OPTIONS = {

module.exports = function (agenda) {
agenda.on('ready', async function() {
agenda.every('2 minutes', 'syncMatriculas', {}, DEFAULT_OPTIONS)
agenda.start()
// agenda.every('2 minutes', 'syncMatriculas', {}, DEFAULT_OPTIONS)
// agenda.start()
})
}
20 changes: 16 additions & 4 deletions app/api/facebook/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,28 @@ const app = require("@/app");
module.exports = async (context) => {
const { ra, email } = context.body;

const user = await app.models.users.findOne({
// Find user by RA first
const user = await app.models.users.findOne({
ra,
$or: [{ "oauth.facebookEmail": email }, { "oauth.email": email }],
$or: [{ "oauth.facebookEmail": email }, { "oauth.email": email }],
'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 80e3efb

Please sign in to comment.