chore: update trySubscribe to async

This commit is contained in:
Ben Allfree 2025-01-10 03:57:33 -08:00
parent b7413091aa
commit a3a60517de

View File

@ -164,20 +164,23 @@ const tryUserSubscribe = (() => {
let unsub: UnsubscribeFunc | undefined
let tid: NodeJS.Timeout | undefined
const _trySubscribe = (id?: string) => {
const _trySubscribe = async (id?: string) => {
clearTimeout(tid)
unsub?.()
unsub = undefined
await unsub?.()
if (!id) return
console.log('Subscribing to user', id)
client()
.client.collection('users')
.subscribe<UserFields>(id, (data) => {
console.log('User subscribed update', data)
userStore.set(data.record)
client().client.collection('users').authRefresh().catch(console.error)
})
.then((u) => {
unsub = u
unsub = async () => {
console.log('Unsubscribing from user', id)
await u()
unsub = undefined
}
})
.catch(() => {
console.error('Failed to subscribe to user')