Allow bot messenger login endpoint to resolve user by email

This commit is contained in:
Ruslan Bakiev
2026-04-02 14:44:50 +07:00
parent 23edfbe7ff
commit dd92172cac

View File

@@ -46,13 +46,24 @@ app.post('/bot/messenger-login', async (req, res) => {
} }
const userId = String(req.body?.userId || '').trim(); const userId = String(req.body?.userId || '').trim();
const email = String(req.body?.email || '').trim().toLowerCase();
const channelId = String(req.body?.channelId || '').trim(); const channelId = String(req.body?.channelId || '').trim();
if (!userId || !channelId) { if (!channelId || (!userId && !email)) {
res.status(400).json({ error: 'userId and channelId are required.' }); res.status(400).json({ error: 'channelId and (userId or email) are required.' });
return; 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) { if (!user) {
res.status(404).json({ error: 'User not found.' }); res.status(404).json({ error: 'User not found.' });
return; return;