Initial commit
This commit is contained in:
18
app/composables/usePocketBase.ts
Normal file
18
app/composables/usePocketBase.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user