refactor(auth): unify messenger bot link flow across login/profile/notifications
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user