@outbuild/supa-store 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +55 -13
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,24 +1,66 @@
1
- # ObSupaStore
1
+ # Supastore
2
2
 
3
- This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 18.2.0.
3
+ A helper library for including angular auth in your Angular app.
4
4
 
5
- ## Code scaffolding
5
+ ## Basic usage, provide in main.ts
6
6
 
7
- Run `ng generate component component-name --project ob-supa-store` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project ob-supa-store`.
8
- > Note: Don't forget to add `--project ob-supa-store` or else it will be added to the default project in your `angular.json` file.
7
+ This will provide the supabase client and the auth object for logged user as signals.
9
8
 
10
- ## Build
9
+ ```typescript
10
+ import { provideSupaStore } from '@outbuild/supa-store'
11
11
 
12
- Run `ng build ob-supa-store` to build the project. The build artifacts will be stored in the `dist/` directory.
12
+ provideSupaStore({
13
+ createClient:{
14
+ supabaseUrl: environment.supabaseUrl,
15
+ supabaseKey: environment.supabaseKey
16
+ }
17
+ })
18
+ ```
13
19
 
14
- ## Publishing
20
+ ## Including Metadata in the user object
15
21
 
16
- After building your library with `ng build ob-supa-store`, go to the dist folder `cd dist/ob-supa-store` and run `npm publish`.
22
+ In many cases users will have metadata that you want to include in the user object. You can do this by providing the 'metadataTable' option. This will automatically fetch the metadata from the table matching the user the 'id' field and include it in the auth object. in most cases this will be the 'users' table.
17
23
 
18
- ## Running unit tests
24
+ There are also instances where you would want to run a custom rpc function to return a auth object, lets imagine custom logic for user, organisation data etc. you can do this by providing the 'metadataRpc' option.
19
25
 
20
- Run `ng test ob-supa-store` to execute the unit tests via [Karma](https://karma-runner.github.io).
26
+ This will run immediatelty after the user is authenticated, either table option, or rpc option not both.
21
27
 
22
- ## Further help
28
+ ```typescript
29
+ import { provideSupaStore } from '@outbuild/supa-store'
30
+
31
+ provideSupaStore({
32
+ createClient:{
33
+ supabaseUrl: environment.supabaseUrl,
34
+ supabaseKey: environment.supabaseKey
35
+ },
36
+ metadataTable: 'users'
37
+ metadataRpc: 'auth_query'
38
+ })
39
+ ```
40
+
41
+ ## Accessing the store
42
+
43
+ ```typescript
44
+ import { injectSupaAuth, injectSupaClient } from '@outbuild/supa-store'
45
+
46
+ auth = injectSupaAuth()
47
+ client = injectSupaClient()
48
+ ```
49
+
50
+ ## Store type
51
+
52
+ ```typescript
53
+ type SupaStoreState = {
54
+ client: SupabaseClient // Supabase Client
55
+ auth: {
56
+ session: Session | undefined | null // Supabase Session
57
+ user: User | undefined | null // Supabase User
58
+ metadata: unknown | undefined | null // Your metadat if provided
59
+ state: {
60
+ prev: AuthChangeEvent | null, // Supabase Auth Change Event
61
+ curr: AuthChangeEvent | null, // Supabase Auth Change Event
62
+ }
63
+ }
64
+ }
65
+ ```
23
66
 
24
- To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@outbuild/supa-store",
3
- "version": "0.1.00",
3
+ "version": "1.0.0",
4
4
  "peerDependencies": {
5
5
  "@angular/common": "^19.2.0",
6
6
  "@angular/core": "^19.2.0",