+ confirm dialog + loginpage throwout
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref, computed } from "vue"
|
||||
import router from "@/router"; // если используешь другой SDK, импорт может отличаться
|
||||
import {useRouter} from "vue-router";
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
// необязательно делать реактивным, но удобно для шаблона
|
||||
const tgApp = ref(window.Telegram.WebApp)
|
||||
const tgData = ref(tgApp.value.initDataUnsafe)
|
||||
const tgData = ref()
|
||||
|
||||
// какие-то удобные вычисления для UI
|
||||
const userId = computed(() => tgApp.value?.user?.id?.toString() ?? "")
|
||||
@@ -13,24 +15,22 @@ const firstName = computed(() => tgData.value?.user?.first_name ?? "")
|
||||
|
||||
onMounted(() => {
|
||||
// сообщаем Telegram WebApp, что UI готов
|
||||
tgData.ready()
|
||||
|
||||
// если есть данные пользователя — положим что-то в localStorage
|
||||
if (tgData.value.user?.id != null) {
|
||||
localStorage.setItem("token", tgData.value.user.id.toString())
|
||||
} else {
|
||||
if (tgApp.initData){
|
||||
tgData.value = tgApp.initDataUnsafe
|
||||
if (tgData.value.user?.id != null) {
|
||||
localStorage.setItem("token", tgData.value.user.id.toString())
|
||||
router.push("/")
|
||||
}
|
||||
}else {
|
||||
localStorage.setItem("token", "123")
|
||||
router.push("/")
|
||||
}
|
||||
// router.push('/')
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-4">
|
||||
<p>Telegram user id: {{ userId || "—" }}</p>
|
||||
<p>Username: {{ username || "—" }}</p>
|
||||
<p>First name: {{ firstName || "—" }}</p>
|
||||
</div>
|
||||
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user