Implement login poll

This commit is contained in:
ekzyis 2023-11-07 17:40:58 +01:00
parent 0e49eb73ee
commit f9a6a86bad
1 changed files with 23 additions and 3 deletions

View File

@ -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) {