refactor(auth): unify messenger bot link flow across login/profile/notifications

This commit is contained in:
Ruslan Bakiev
2026-04-02 16:12:34 +07:00
parent b0f461a74e
commit f4a4b41dd5
4 changed files with 21 additions and 18 deletions

View File

@@ -5,6 +5,7 @@ import {
RequestLoginCodeDocument,
VerifyLoginCodeDocument,
} from '~/composables/graphql/generated';
import { buildMessengerBotStartUrl } from '~/composables/useMessengerBotLink';
const config = useRuntimeConfig();
const route = useRoute();
@@ -35,18 +36,12 @@ const maxBotUrl = computed(() => config.public.maxBotUrl || '');
const normalizedEmail = computed(() => email.value.trim().toLowerCase());
const isEmailReady = computed(() => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(normalizedEmail.value));
function buildBotLoginUrl(baseUrl: string) {
if (!isEmailReady.value || !baseUrl) {
return '';
}
const payload = encodeURIComponent(`login:${normalizedEmail.value}`);
const separator = baseUrl.includes('?') ? '&' : '?';
return `${baseUrl}${separator}start=${payload}`;
}
const telegramLoginUrl = computed(() => buildBotLoginUrl(telegramBotUrl.value));
const maxLoginUrl = computed(() => buildBotLoginUrl(maxBotUrl.value));
const telegramLoginUrl = computed(() =>
isEmailReady.value ? buildMessengerBotStartUrl(telegramBotUrl.value, normalizedEmail.value) : '',
);
const maxLoginUrl = computed(() =>
isEmailReady.value ? buildMessengerBotStartUrl(maxBotUrl.value, normalizedEmail.value) : '',
);
async function finalizeSession(accessToken: string) {
authCookie.value = accessToken;