mirror of
https://github.com/pockethost/pockethost.git
synced 2025-11-24 14:35:49 +00:00
enh(dashboard): improve logging for user and instance subscriptions
This commit is contained in:
parent
876a44092f
commit
51c361aec6
@ -92,15 +92,16 @@ export const init = () => {
|
|||||||
|
|
||||||
onAuthChange((authStoreProps) => {
|
onAuthChange((authStoreProps) => {
|
||||||
const isLoggedIn = authStoreProps.isValid
|
const isLoggedIn = authStoreProps.isValid
|
||||||
isUserLoggedIn.set(isLoggedIn)
|
console.log(`onAuthChange update`, { isLoggedIn, authStoreProps })
|
||||||
const user = authStoreProps.model as UserFields
|
const user = authStoreProps.model as UserFields
|
||||||
userStore.set(isLoggedIn ? user : undefined)
|
userStore.set(isLoggedIn ? user : undefined)
|
||||||
isAuthStateInitialized.set(true)
|
isAuthStateInitialized.set(true)
|
||||||
|
isUserLoggedIn.set(isLoggedIn)
|
||||||
tryUserSubscribe(user?.id)
|
tryUserSubscribe(user?.id)
|
||||||
})
|
})
|
||||||
|
|
||||||
userStore.subscribe((user) => {
|
userStore.subscribe((user) => {
|
||||||
console.log(`userStore.subscribe`, { user })
|
console.log(`userStore.subscribe update`, { user })
|
||||||
const isPaid = [SubscriptionType.Founder, SubscriptionType.Premium, SubscriptionType.Flounder].includes(
|
const isPaid = [SubscriptionType.Founder, SubscriptionType.Premium, SubscriptionType.Flounder].includes(
|
||||||
user?.subscription || SubscriptionType.Free
|
user?.subscription || SubscriptionType.Free
|
||||||
)
|
)
|
||||||
@ -113,22 +114,25 @@ export const init = () => {
|
|||||||
// This holds an array of all the user's instances and their data
|
// This holds an array of all the user's instances and their data
|
||||||
|
|
||||||
/** Listen for instances */
|
/** Listen for instances */
|
||||||
|
let unsubInstanceWatch: UnsubscribeFunc | undefined
|
||||||
isUserLoggedIn.subscribe(async (isLoggedIn) => {
|
isUserLoggedIn.subscribe(async (isLoggedIn) => {
|
||||||
let unsub: UnsubscribeFunc | undefined
|
console.log(`isUserLoggedIn.subscribe update`, { isLoggedIn })
|
||||||
if (!isLoggedIn) {
|
if (!isLoggedIn) {
|
||||||
userStore.set(undefined)
|
userStore.set(undefined)
|
||||||
globalInstancesStore.set({})
|
globalInstancesStore.set({})
|
||||||
globalInstancesStoreReady.set(false)
|
globalInstancesStoreReady.set(false)
|
||||||
unsub?.()
|
unsubInstanceWatch?.()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
unsub = undefined
|
unsubInstanceWatch = undefined
|
||||||
})
|
})
|
||||||
.catch(console.error)
|
.catch(console.error)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const { getAllInstancesById } = client()
|
const { getAllInstancesById } = client()
|
||||||
|
|
||||||
|
console.log('Getting all instances by ID')
|
||||||
const instances = await getAllInstancesById()
|
const instances = await getAllInstancesById()
|
||||||
|
console.log('Instances', instances)
|
||||||
|
|
||||||
globalInstancesStore.set(instances)
|
globalInstancesStore.set(instances)
|
||||||
globalInstancesStoreReady.set(true)
|
globalInstancesStoreReady.set(true)
|
||||||
@ -137,13 +141,14 @@ export const init = () => {
|
|||||||
client()
|
client()
|
||||||
.client.collection('instances')
|
.client.collection('instances')
|
||||||
.subscribe<InstanceFields>('*', (data) => {
|
.subscribe<InstanceFields>('*', (data) => {
|
||||||
|
console.log('Instance subscribe update', data)
|
||||||
globalInstancesStore.update((instances) => {
|
globalInstancesStore.update((instances) => {
|
||||||
instances[data.record.id] = data.record
|
instances[data.record.id] = data.record
|
||||||
return instances
|
return instances
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.then((u) => {
|
.then((u) => {
|
||||||
unsub = u
|
unsubInstanceWatch = u
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
console.error('Failed to subscribe to instances')
|
console.error('Failed to subscribe to instances')
|
||||||
@ -171,6 +176,7 @@ const tryUserSubscribe = (() => {
|
|||||||
client().client.collection('users').authRefresh().catch(console.error)
|
client().client.collection('users').authRefresh().catch(console.error)
|
||||||
})
|
})
|
||||||
.then((u) => {
|
.then((u) => {
|
||||||
|
console.log('Subscribed to user', id)
|
||||||
unsub = async () => {
|
unsub = async () => {
|
||||||
console.log('Unsubscribing from user', id)
|
console.log('Unsubscribing from user', id)
|
||||||
await u()
|
await u()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user