30 lines
758 B
TypeScript
30 lines
758 B
TypeScript
import { defineStore } from 'pinia'
|
|
import { ref } from 'vue'
|
|
import { api } from 'boot/axios'
|
|
import type { WebApp } from '@twa-dev/types'
|
|
|
|
export const useAuthStore = defineStore('auth', () => {
|
|
const isInit = ref(false)
|
|
const telegramUserData = ref()
|
|
|
|
async function init (tg: WebApp) {
|
|
await api.post('/auth?' + tg?.initData)
|
|
telegramUserData.value = tg?.initDataUnsafe.user
|
|
isInit.value = true
|
|
}
|
|
|
|
const startRouteInfo = ref<{ id: number; taskId?: number; meetingId?: number } | null>(null)
|
|
|
|
function setStartRouteInfo (info: { id: number; taskId?: number; meetingId?: number } | null) {
|
|
startRouteInfo.value = info
|
|
}
|
|
|
|
return {
|
|
isInit,
|
|
telegramUserData,
|
|
startRouteInfo,
|
|
setStartRouteInfo,
|
|
init
|
|
}
|
|
})
|