feat(auth): support bot-managed messenger login flow
This commit is contained in:
@@ -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,17 +141,19 @@ 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)}`;
|
||||||
|
|
||||||
const dispatch = await sendMessengerMessage({
|
if (!skipDispatch) {
|
||||||
type: channel,
|
const dispatch = await sendMessengerMessage({
|
||||||
channelId,
|
type: channel,
|
||||||
message: 'Вход подтвержден. Нажмите кнопку, чтобы открыть личный кабинет.',
|
channelId,
|
||||||
buttonUrl: loginUrl,
|
message: 'Вход подтвержден. Нажмите кнопку, чтобы открыть личный кабинет.',
|
||||||
buttonText: 'Открыть кабинет',
|
buttonUrl: loginUrl,
|
||||||
});
|
buttonText: 'Открыть кабинет',
|
||||||
|
});
|
||||||
|
|
||||||
if (!dispatch.success) {
|
if (!dispatch.success) {
|
||||||
res.status(502).json({ error: dispatch.detail });
|
res.status(502).json({ error: dispatch.detail });
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
|
|||||||
Reference in New Issue
Block a user