@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.
- package/README.md +55 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,24 +1,66 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Supastore
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A helper library for including angular auth in your Angular app.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Basic usage, provide in main.ts
|
|
6
6
|
|
|
7
|
-
|
|
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
|
-
|
|
9
|
+
```typescript
|
|
10
|
+
import { provideSupaStore } from '@outbuild/supa-store'
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
provideSupaStore({
|
|
13
|
+
createClient:{
|
|
14
|
+
supabaseUrl: environment.supabaseUrl,
|
|
15
|
+
supabaseKey: environment.supabaseKey
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
```
|
|
13
19
|
|
|
14
|
-
##
|
|
20
|
+
## Including Metadata in the user object
|
|
15
21
|
|
|
16
|
-
|
|
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
|
-
|
|
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
|
-
|
|
26
|
+
This will run immediatelty after the user is authenticated, either table option, or rpc option not both.
|
|
21
27
|
|
|
22
|
-
|
|
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.
|