Files
shiftcraft/app/composables/usePocketBase.ts
2026-04-17 23:26:01 +00:00

19 lines
616 B
TypeScript

import type { ReactiveAuthStore } from '~/plugins/pocketbase'
/**
* Returns the PocketBase client and a reactive ref of the auth store.
*/
export const usePocketBase = () => {
const { $pb } = useNuxtApp()
if (!$pb) throw new Error('Pocketbase plugin not accessible')
return {
pb: $pb,
/**
* Reactive wrapper around the PocketBase auth store.
* Access state via `authStore.value.isValid`, `.record`, `.token`, `.isSuperuser` etc.
* Use only for reactive access; for imperative methods use `$pb.authStore` directly.
*/
authStore: ($pb.authStore as ReactiveAuthStore).ref
}
}