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 email = String(req.body?.email || '').trim().toLowerCase();
const channelId = String(req.body?.channelId || '').trim();
const skipDispatch = req.body?.skipDispatch === true;
if (!channelId || (!userId && !email)) {
res.status(400).json({ error: 'channelId and (userId or email) are required.' });
return;
@@ -140,17 +141,19 @@ app.post('/bot/messenger-login', async (req, res) => {
).replace(/\/$/, '');
const loginUrl = `${frontendUrl}/login?login_token=${encodeURIComponent(login.loginToken)}`;
const dispatch = await sendMessengerMessage({
type: channel,
channelId,
message: 'Вход подтвержден. Нажмите кнопку, чтобы открыть личный кабинет.',
buttonUrl: loginUrl,
buttonText: 'Открыть кабинет',
});
if (!skipDispatch) {
const dispatch = await sendMessengerMessage({
type: channel,
channelId,
message: 'Вход подтвержден. Нажмите кнопку, чтобы открыть личный кабинет.',
buttonUrl: loginUrl,
buttonText: 'Открыть кабинет',
});
if (!dispatch.success) {
res.status(502).json({ error: dispatch.detail });
return;
if (!dispatch.success) {
res.status(502).json({ error: dispatch.detail });
return;
}
}
res.json({