diff --git a/vue/src/components/LoginQRCode.vue b/vue/src/components/LoginQRCode.vue index 863f8ab..0746eba 100644 --- a/vue/src/components/LoginQRCode.vue +++ b/vue/src/components/LoginQRCode.vue @@ -9,18 +9,38 @@ import { ref } from 'vue' import { useSession } from '@/stores/session' import { useRouter } from 'vue-router' +const router = useRouter() +const session = useSession() + const qr = ref(null) const lnurl = ref(null) +let interval = null +const LOGIN_POLL = 2000 + +const poll = async () => { + try { + await session.checkSession() + if (session.isAuthenticated) { + // TODO schedule redirect + clearInterval(interval) + router.push('/') + } + } catch (err) { + if (err.reason === 'session not found') { + // ignore + } else { + console.error(err) + } + } +} const login = async () => { const s = await session.login() qr.value = s.qr lnurl.value = s.lnurl + interval = setInterval(poll, LOGIN_POLL) } -const router = useRouter() -const session = useSession() - await (async () => { // redirect to / if session already exists if (session.initialized) {