feat(auth): support bot-managed messenger login flow

This commit is contained in:
Ruslan Bakiev
2026-04-03 16:55:14 +07:00
parent f8b470f77d
commit c7908041ba

View File

@@ -90,6 +90,7 @@ 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 email = String(req.body?.email || '').trim().toLowerCase();
const channelId = String(req.body?.channelId || '').trim(); const channelId = String(req.body?.channelId || '').trim();
const skipDispatch = req.body?.skipDispatch === true;
if (!channelId || (!userId && !email)) { if (!channelId || (!userId && !email)) {
res.status(400).json({ error: 'channelId and (userId or email) are required.' }); res.status(400).json({ error: 'channelId and (userId or email) are required.' });
return; return;
@@ -140,6 +141,7 @@ app.post('/bot/messenger-login', async (req, res) => {
).replace(/\/$/, ''); ).replace(/\/$/, '');
const loginUrl = `${frontendUrl}/login?login_token=${encodeURIComponent(login.loginToken)}`; const loginUrl = `${frontendUrl}/login?login_token=${encodeURIComponent(login.loginToken)}`;
if (!skipDispatch) {
const dispatch = await sendMessengerMessage({ const dispatch = await sendMessengerMessage({
type: channel, type: channel,
channelId, channelId,
@@ -152,6 +154,7 @@ app.post('/bot/messenger-login', async (req, res) => {
res.status(502).json({ error: dispatch.detail }); res.status(502).json({ error: dispatch.detail });
return; return;
} }
}
res.json({ res.json({
ok: true, ok: true,