diff --git a/src/server.js b/src/server.js index d6c0dcd..27d5514 100644 --- a/src/server.js +++ b/src/server.js @@ -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;