This commit is contained in:
xds
2025-10-27 17:02:59 +03:00
parent 99890102ef
commit 1963f06cc7
3 changed files with 14 additions and 8 deletions

View File

@@ -1,27 +1,27 @@
<script setup lang="ts">
import { onMounted, ref, computed } from "vue"
import { WebApp } from "@grammyjs/web-app"
import router from "@/router"; // если используешь другой SDK, импорт может отличаться
// необязательно делать реактивным, но удобно для шаблона
const tgData = ref(WebApp.initDataUnsafe)
const tgApp = ref(window.Telegram.WebApp)
const tgData = ref(tgApp.value.initDataUnsafe)
// какие-то удобные вычисления для UI
const userId = computed(() => tgData.value?.user?.id?.toString() ?? "")
const username = computed(() => tgData.value?.user?.username ?? "")
const userId = computed(() => tgApp.value?.user?.id?.toString() ?? "")
const username = computed(() => tgApp.value?.user?.username ?? "")
const firstName = computed(() => tgData.value?.user?.first_name ?? "")
onMounted(() => {
// сообщаем Telegram WebApp, что UI готов
WebApp.ready()
tgData.ready()
// если есть данные пользователя — положим что-то в localStorage
if (tgData.value?.user?.id != null) {
if (tgData.value.user?.id != null) {
localStorage.setItem("token", tgData.value.user.id.toString())
} else {
localStorage.setItem("token", "123")
}
router.push('/')
// router.push('/')
})
</script>