feat(auth): request secure messenger start sessions
This commit is contained in:
@@ -4,7 +4,7 @@ import {
|
||||
MeDocument,
|
||||
MyMessengerConnectionsDocument,
|
||||
} from '~/composables/graphql/generated';
|
||||
import { buildMessengerBotStartUrl } from '~/composables/useMessengerBotLink';
|
||||
import { useMessengerStart } from '~/composables/useMessengerStart';
|
||||
|
||||
type MessengerItem = {
|
||||
type: 'TELEGRAM' | 'MAX';
|
||||
@@ -15,6 +15,7 @@ type MessengerItem = {
|
||||
const config = useRuntimeConfig();
|
||||
const meQuery = useQuery(MeDocument);
|
||||
const connectionsQuery = useQuery(MyMessengerConnectionsDocument);
|
||||
const { openMessengerBot, pendingChannel } = useMessengerStart();
|
||||
|
||||
const telegramConnection = computed(() =>
|
||||
connectionsQuery.result.value?.myMessengerConnections?.find(
|
||||
@@ -34,11 +35,23 @@ function buildBotConnectUrl(baseUrl: string) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return buildMessengerBotStartUrl(baseUrl, accountEmail);
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
const telegramConnectUrl = computed(() => buildBotConnectUrl(config.public.telegramBotUrl || ''));
|
||||
const maxConnectUrl = computed(() => buildBotConnectUrl(config.public.maxBotUrl || ''));
|
||||
|
||||
async function connectMessenger(channel: 'TELEGRAM' | 'MAX') {
|
||||
const baseUrl = channel === 'TELEGRAM' ? telegramConnectUrl.value : maxConnectUrl.value;
|
||||
if (!baseUrl) {
|
||||
return;
|
||||
}
|
||||
|
||||
await openMessengerBot({
|
||||
channel,
|
||||
baseUrl,
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -57,15 +70,20 @@ const maxConnectUrl = computed(() => buildBotConnectUrl(config.public.maxBotUrl
|
||||
<p class="text-sm opacity-80">
|
||||
{{ telegramConnection ? `Подключен: ${telegramConnection.channelId}` : 'Не подключен' }}
|
||||
</p>
|
||||
<a
|
||||
:href="telegramConnectUrl || undefined"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
<button
|
||||
class="btn btn-secondary mt-3 w-full"
|
||||
:class="{ 'btn-disabled pointer-events-none': !telegramConnectUrl }"
|
||||
:disabled="pendingChannel === 'TELEGRAM' || !telegramConnectUrl"
|
||||
@click="connectMessenger('TELEGRAM')"
|
||||
>
|
||||
{{ telegramConnection ? 'Переподключить Telegram' : 'Подключить Telegram' }}
|
||||
</a>
|
||||
{{
|
||||
pendingChannel === 'TELEGRAM'
|
||||
? 'Открываем Telegram…'
|
||||
: telegramConnection
|
||||
? 'Переподключить Telegram'
|
||||
: 'Подключить Telegram'
|
||||
}}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="rounded-2xl bg-[#f8fbf9] p-4 transition hover:shadow-md">
|
||||
@@ -73,15 +91,20 @@ const maxConnectUrl = computed(() => buildBotConnectUrl(config.public.maxBotUrl
|
||||
<p class="text-sm opacity-80">
|
||||
{{ maxConnection ? `Подключен: ${maxConnection.channelId}` : 'Не подключен' }}
|
||||
</p>
|
||||
<a
|
||||
:href="maxConnectUrl || undefined"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
<button
|
||||
class="btn btn-accent mt-3 w-full"
|
||||
:class="{ 'btn-disabled pointer-events-none': !maxConnectUrl }"
|
||||
:disabled="pendingChannel === 'MAX' || !maxConnectUrl"
|
||||
@click="connectMessenger('MAX')"
|
||||
>
|
||||
{{ maxConnection ? 'Переподключить Max' : 'Подключить Max' }}
|
||||
</a>
|
||||
{{
|
||||
pendingChannel === 'MAX'
|
||||
? 'Открываем Max…'
|
||||
: maxConnection
|
||||
? 'Переподключить Max'
|
||||
: 'Подключить Max'
|
||||
}}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user