Allow bot messenger login endpoint to resolve user by email
This commit is contained in:
@@ -46,13 +46,24 @@ app.post('/bot/messenger-login', async (req, res) => {
|
||||
}
|
||||
|
||||
const userId = String(req.body?.userId || '').trim();
|
||||
const email = String(req.body?.email || '').trim().toLowerCase();
|
||||
const channelId = String(req.body?.channelId || '').trim();
|
||||
if (!userId || !channelId) {
|
||||
res.status(400).json({ error: 'userId and channelId are required.' });
|
||||
if (!channelId || (!userId && !email)) {
|
||||
res.status(400).json({ error: 'channelId and (userId or email) are required.' });
|
||||
return;
|
||||
}
|
||||
|
||||
const user = await prisma.user.findUnique({ where: { id: userId } });
|
||||
const user = userId
|
||||
? await prisma.user.findUnique({ where: { id: userId } })
|
||||
: await prisma.user.findFirst({
|
||||
where: {
|
||||
email: {
|
||||
equals: email,
|
||||
mode: 'insensitive',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
res.status(404).json({ error: 'User not found.' });
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user