@outbuild/supa-store 1.0.3 → 1.0.5
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 +29 -16
- package/fesm2022/outbuild-supa-store.mjs +15 -2
- package/fesm2022/outbuild-supa-store.mjs.map +1 -1
- package/lib/common/features/supa-store-core.feature.d.ts +14 -6
- package/lib/common/type/supa-store.types.d.ts +3 -3
- package/lib/supa-store.provider.d.ts +9 -9
- package/lib/supa-store.store.d.ts +10 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# Supastore
|
|
2
2
|
|
|
3
|
-
A helper library for including Supabase with auth as signals in your Angular app,
|
|
3
|
+
A helper library for including Supabase with auth as signals in your Angular app,
|
|
4
|
+
it uses @ngrx/signals more examples to come.
|
|
4
5
|
|
|
5
6
|
## Basic usage, provide in main.ts
|
|
6
7
|
|
|
@@ -19,11 +20,14 @@ provideSupaStore({
|
|
|
19
20
|
|
|
20
21
|
## Including Metadata in the user object
|
|
21
22
|
|
|
22
|
-
In many cases users will have metadata that you want to include in the user object.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
In many cases users will have metadata that you want to include in the user object.
|
|
24
|
+
You can do this by providing the 'metadataTable' option. This will automatically fetch
|
|
25
|
+
the metadata from the table matching the user the 'id' field and include it in the auth
|
|
26
|
+
object. in most cases this will be the 'users' table. There are also instances where
|
|
27
|
+
you would want to run a custom rpc function to return a auth object, lets imagine custom
|
|
28
|
+
logic for user, organisation data etc. you can do this by providing the 'metadataRpc' option.
|
|
29
|
+
This will run immediatelty after the user is authenticated, either table option, or rpc
|
|
30
|
+
option not both.
|
|
27
31
|
|
|
28
32
|
```typescript
|
|
29
33
|
import { provideSupaStore } from '@outbuild/supa-store'
|
|
@@ -42,26 +46,35 @@ provideSupaStore({
|
|
|
42
46
|
## Accessing the store
|
|
43
47
|
|
|
44
48
|
```typescript
|
|
45
|
-
import { injectSupaAuth, injectSupaClient } from '@outbuild/supa-store'
|
|
49
|
+
import { SupaStore, injectSupaAuth, injectSupaClient } from '@outbuild/supa-store'
|
|
46
50
|
|
|
51
|
+
store = inject(SupaStore)
|
|
47
52
|
auth = injectSupaAuth()
|
|
48
53
|
client = injectSupaClient()
|
|
54
|
+
|
|
49
55
|
```
|
|
50
56
|
|
|
57
|
+
## Observables
|
|
58
|
+
|
|
59
|
+
Observables will return either null or the value, if the value is null, it means the
|
|
60
|
+
user is not authenticated.
|
|
61
|
+
|
|
51
62
|
## Store type
|
|
52
63
|
|
|
53
64
|
```typescript
|
|
54
65
|
type SupaStoreState = {
|
|
55
|
-
client: SupabaseClient
|
|
66
|
+
client: SupabaseClient
|
|
56
67
|
auth: {
|
|
57
|
-
session:
|
|
58
|
-
user:
|
|
59
|
-
metadata:
|
|
60
|
-
state: {
|
|
61
|
-
prev: AuthChangeEvent | null
|
|
62
|
-
curr: AuthChangeEvent | null
|
|
68
|
+
session: undefined | null | Session
|
|
69
|
+
user: undefined | null | User
|
|
70
|
+
metadata: undefined | null | unknown
|
|
71
|
+
state: {
|
|
72
|
+
prev: AuthChangeEvent | null
|
|
73
|
+
curr: AuthChangeEvent | null
|
|
63
74
|
}
|
|
64
|
-
}
|
|
75
|
+
},
|
|
76
|
+
user$?: Observable<null | User>
|
|
77
|
+
session$?: Observable<null | Session>
|
|
78
|
+
metadata$?: Observable<null | unknown>
|
|
65
79
|
}
|
|
66
80
|
```
|
|
67
|
-
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { signalStoreFeature, type, withMethods, withHooks, withState, signalStore } from '@ngrx/signals';
|
|
1
|
+
import { signalStoreFeature, type, withMethods, withHooks, withState, withProps, signalStore } from '@ngrx/signals';
|
|
2
2
|
import { InjectionToken, inject, makeEnvironmentProviders } from '@angular/core';
|
|
3
3
|
import { updateState, withDevtools } from '@angular-architects/ngrx-toolkit';
|
|
4
4
|
import { createClient } from '@supabase/supabase-js';
|
|
5
5
|
import { toObservable } from '@angular/core/rxjs-interop';
|
|
6
6
|
import { firstValueFrom, filter } from 'rxjs';
|
|
7
|
+
import { WA_WINDOW, WA_SCREEN } from '@ng-web-apis/common';
|
|
7
8
|
import { createInjectionToken } from 'ngxtension/create-injection-token';
|
|
8
9
|
|
|
9
10
|
const SUPA_STORE_OPTIONS = new InjectionToken('SUPA_STORE_OPTIONS');
|
|
@@ -52,7 +53,13 @@ const withPostAuth = () => signalStoreFeature({
|
|
|
52
53
|
}
|
|
53
54
|
}));
|
|
54
55
|
|
|
55
|
-
const withSupaStoreCore = () => signalStoreFeature(withDevtools('supaStore'), withState(() => inject(INITIAL_STATE)), withPostAuth(),
|
|
56
|
+
const withSupaStoreCore = () => signalStoreFeature(withDevtools('supaStore'), withState(() => inject(INITIAL_STATE)), withPostAuth(), withProps(({ auth: { user, session, metadata } }) => ({
|
|
57
|
+
_SCREEN: inject(WA_SCREEN),
|
|
58
|
+
_WINDOW: inject(WA_WINDOW),
|
|
59
|
+
user$: toObservable(user).pipe(filter(res => res !== undefined)),
|
|
60
|
+
session$: toObservable(session).pipe(filter(res => res !== undefined)),
|
|
61
|
+
metadata$: toObservable(metadata).pipe(filter(res => res !== undefined))
|
|
62
|
+
})), withMethods(store => ({
|
|
56
63
|
_initSession: async () => {
|
|
57
64
|
const { data: { session }, error } = await store.client().auth.getSession();
|
|
58
65
|
updateState(store, 'Initialise Session', { auth: { ...store.auth(), session } });
|
|
@@ -60,6 +67,12 @@ const withSupaStoreCore = () => signalStoreFeature(withDevtools('supaStore'), wi
|
|
|
60
67
|
_initUser: async () => {
|
|
61
68
|
const { data: { user }, error } = await store.client().auth.getUser();
|
|
62
69
|
updateState(store, 'Initialise User', { auth: { ...store.auth(), user } });
|
|
70
|
+
},
|
|
71
|
+
signInWithGoogle: async (options = {}) => {
|
|
72
|
+
const { data: { url }, error } = await store.client().auth.signInWithOAuth({ provider: 'google', ...options });
|
|
73
|
+
const [width, height] = [500, 600];
|
|
74
|
+
const [left, top] = [(store._SCREEN.width / 2) - (width / 2), (store._SCREEN.height / 2) - (height / 2)];
|
|
75
|
+
store._WINDOW.open(url, '_blank', `width=${width},height=${height},left=${left},top=${top},toolbar=no,menubar=no`);
|
|
63
76
|
}
|
|
64
77
|
})), withHooks({
|
|
65
78
|
onInit(store) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outbuild-supa-store.mjs","sources":["../../../projects/ob-supa-store/src/lib/common/token/supabase-credentials.token.ts","../../../projects/ob-supa-store/src/lib/common/token/initial-state.token.ts","../../../projects/ob-supa-store/src/lib/common/features/post-auth-loader.feature.ts","../../../projects/ob-supa-store/src/lib/common/features/supa-store-core.feature.ts","../../../projects/ob-supa-store/src/lib/supa-store.store.ts","../../../projects/ob-supa-store/src/lib/supa-store.provider.ts","../../../projects/ob-supa-store/src/public-api.ts","../../../projects/ob-supa-store/src/outbuild-supa-store.ts"],"sourcesContent":["import { InjectionToken } from \"@angular/core\"\r\nimport { SupaStoreOptions } from \"../type/supa-store.types\"\r\n\r\nexport const SUPA_STORE_OPTIONS = new InjectionToken<SupaStoreOptions>('SUPA_STORE_OPTIONS')\r\n","import { inject, InjectionToken } from \"@angular/core\"\r\nimport { SUPA_STORE_OPTIONS } from \"./supabase-credentials.token\"\r\nimport { createClient } from \"@supabase/supabase-js\"\r\nimport { SupaStoreState } from \"../type/supa-store.types\"\r\n\r\nexport const INITIAL_STATE = new InjectionToken<SupaStoreState>('SupaStoreState', {\r\n factory: () => {\r\n\r\n const { createClient: { supabaseUrl, supabaseKey, options }} = inject(SUPA_STORE_OPTIONS)\r\n const client = createClient(supabaseUrl, supabaseKey, options)\r\n\r\n return {\r\n client,\r\n auth: {\r\n session: undefined,\r\n user: undefined,\r\n metadata: undefined,\r\n state: { prev: null, curr: null }\r\n }\r\n }\r\n\r\n }\r\n})\r\n","import { inject } from '@angular/core'\r\nimport { Session } from '@supabase/supabase-js'\r\nimport { toObservable } from \"@angular/core/rxjs-interop\"\r\nimport { SupaStoreState } from '../type/supa-store.types'\r\nimport { SUPA_STORE_OPTIONS } from '../token/supabase-credentials.token'\r\nimport { filter, firstValueFrom, Observable } from 'rxjs'\r\nimport { signalStoreFeature, type, withHooks, withMethods } from '@ngrx/signals'\r\nimport { updateState } from '@angular-architects/ngrx-toolkit'\r\n\r\nexport const withPostAuth = () => signalStoreFeature(\r\n\r\n {\r\n state: type<SupaStoreState>()\r\n },\r\n\r\n withMethods((store, { metadataRpc: rpc, metadataTable: table } = inject(SUPA_STORE_OPTIONS)) => ({\r\n\r\n _postAuth: async () => {\r\n\r\n if (table || rpc) {\r\n\r\n const session = await firstValueFrom(toObservable(store.auth.session).pipe(filter(res => res !== undefined)) as Observable<Session>)\r\n if (!session) return\r\n\r\n if (table) {\r\n const { data } = await store.client().from(table).select('*').eq('id', session?.user?.id).single()\r\n updateState(store, 'Load Metadata - Table', { auth: { ...store.auth(), metadata: data }})\r\n } else if (rpc) {\r\n const { data } = await store.client().rpc(rpc, { input: { user_id: session?.user?.id }})\r\n updateState(store, 'Load Metadata - Rpc', { auth: { ...store.auth(), metadata: data }})\r\n } else {\r\n updateState(store, 'No Metadata', { auth: { ...store.auth(), metadata: null}})\r\n }\r\n\r\n }\r\n },\r\n\r\n })),\r\n\r\n withHooks({\r\n\r\n onInit(store) {\r\n\r\n /* Auto Load Additional User Auth Data */\r\n store._postAuth()\r\n\r\n }\r\n\r\n })\r\n\r\n)\r\n","import { inject } from '@angular/core';\r\nimport { updateState, withDevtools } from '@angular-architects/ngrx-toolkit'\r\nimport { INITIAL_STATE } from '../token/initial-state.token'\r\nimport { SupaStoreState } from '../type/supa-store.types'\r\nimport { withPostAuth } from '../features/post-auth-loader.feature'\r\nimport { signalStoreFeature, withHooks, withMethods, withState } from '@ngrx/signals'\r\n\r\nexport const withSupaStoreCore = () => signalStoreFeature(\r\n\r\n withDevtools('supaStore'),\r\n withState<SupaStoreState>(() => inject(INITIAL_STATE)),\r\n withPostAuth(),\r\n\r\n withMethods(store => ({\r\n\r\n _initSession: async () => {\r\n const { data: { session }, error} = await store.client().auth.getSession()\r\n updateState(store, 'Initialise Session', { auth: { ...store.auth(), session }})\r\n },\r\n\r\n _initUser: async () => {\r\n const { data: { user }, error } = await store.client().auth.getUser()\r\n updateState(store, 'Initialise User', { auth: { ...store.auth(), user }})\r\n }\r\n\r\n })),\r\n\r\n withHooks({\r\n\r\n onInit(store) {\r\n\r\n /* Listen For Auth State Changes */\r\n store.client().auth.onAuthStateChange(state => {\r\n updateState(store, 'Auth State Change', { auth: { ...store.auth(), state: { prev: store.auth.state.curr(), curr: state }}})\r\n })\r\n\r\n /* Init Supabase Session */\r\n store._initSession()\r\n\r\n /* Init Supabase User */\r\n store._initUser()\r\n\r\n }\r\n\r\n })\r\n\r\n)\r\n","import { signalStore } from '@ngrx/signals'\r\nimport { withSupaStoreCore } from './common/features/supa-store-core.feature'\r\n\r\nexport const SupaStore = signalStore(\r\n withSupaStoreCore()\r\n)\r\n","import { EnvironmentProviders, inject, makeEnvironmentProviders } from \"@angular/core\"\r\nimport { SupaStore } from \"./supa-store.store\"\r\nimport { SUPA_STORE_OPTIONS } from \"./common/token/supabase-credentials.token\"\r\nimport { SupaStoreOptions } from \"./common/type/supa-store.types\"\r\nimport { createInjectionToken } from 'ngxtension/create-injection-token'\r\n\r\n\r\nexport const provideSupaStore = (options: SupaStoreOptions): EnvironmentProviders => makeEnvironmentProviders([\r\n {\r\n provide: SUPA_STORE_OPTIONS,\r\n useValue: options\r\n },\r\n SupaStore\r\n])\r\n\r\n\r\nexport const [ injectSupaClient ] = createInjectionToken(() => inject(SupaStore).client)\r\nexport const [ injectSupaAuth ] = createInjectionToken(() => inject(SupaStore).auth)\r\n","/*\r\n * Public API Surface of ob-supa-store\r\n*/\r\n\r\nexport * from './lib/supa-store.store'\r\nexport * from './lib/supa-store.provider'\r\nexport * from './lib/common/features/supa-store-core.feature'\r\nexport * from './lib/common/type/supa-store.types'\r\n","/**\n * Generated bundle index. Do not edit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,MAAA,CAAE,cAAc,CAAE,GAAK,oBAAoB,CAAC,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI;;ACjBrF;;AAEE;;ACFF;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"outbuild-supa-store.mjs","sources":["../../../projects/ob-supa-store/src/lib/common/token/supabase-credentials.token.ts","../../../projects/ob-supa-store/src/lib/common/token/initial-state.token.ts","../../../projects/ob-supa-store/src/lib/common/features/post-auth-loader.feature.ts","../../../projects/ob-supa-store/src/lib/common/features/supa-store-core.feature.ts","../../../projects/ob-supa-store/src/lib/supa-store.store.ts","../../../projects/ob-supa-store/src/lib/supa-store.provider.ts","../../../projects/ob-supa-store/src/public-api.ts","../../../projects/ob-supa-store/src/outbuild-supa-store.ts"],"sourcesContent":["import { InjectionToken } from \"@angular/core\"\r\nimport { SupaStoreOptions } from \"../type/supa-store.types\"\r\n\r\nexport const SUPA_STORE_OPTIONS = new InjectionToken<SupaStoreOptions>('SUPA_STORE_OPTIONS')\r\n","import { inject, InjectionToken } from \"@angular/core\"\r\nimport { SUPA_STORE_OPTIONS } from \"./supabase-credentials.token\"\r\nimport { createClient } from \"@supabase/supabase-js\"\r\nimport { SupaStoreState } from \"../type/supa-store.types\"\r\n\r\nexport const INITIAL_STATE = new InjectionToken<SupaStoreState>('SupaStoreState', {\r\n factory: () => {\r\n\r\n const { createClient: { supabaseUrl, supabaseKey, options }} = inject(SUPA_STORE_OPTIONS)\r\n const client = createClient(supabaseUrl, supabaseKey, options)\r\n\r\n return {\r\n client,\r\n auth: {\r\n session: undefined,\r\n user: undefined,\r\n metadata: undefined,\r\n state: { prev: null, curr: null }\r\n }\r\n }\r\n\r\n }\r\n})\r\n","import { inject } from '@angular/core'\r\nimport { Session } from '@supabase/supabase-js'\r\nimport { toObservable } from \"@angular/core/rxjs-interop\"\r\nimport { SupaStoreState } from '../type/supa-store.types'\r\nimport { SUPA_STORE_OPTIONS } from '../token/supabase-credentials.token'\r\nimport { filter, firstValueFrom, Observable } from 'rxjs'\r\nimport { signalStoreFeature, type, withHooks, withMethods } from '@ngrx/signals'\r\nimport { updateState } from '@angular-architects/ngrx-toolkit'\r\n\r\nexport const withPostAuth = () => signalStoreFeature(\r\n\r\n {\r\n state: type<SupaStoreState>()\r\n },\r\n\r\n withMethods((store, { metadataRpc: rpc, metadataTable: table } = inject(SUPA_STORE_OPTIONS)) => ({\r\n\r\n _postAuth: async () => {\r\n\r\n if (table || rpc) {\r\n\r\n const session = await firstValueFrom(toObservable(store.auth.session).pipe(filter(res => res !== undefined)) as Observable<Session>)\r\n if (!session) return\r\n\r\n if (table) {\r\n const { data } = await store.client().from(table).select('*').eq('id', session?.user?.id).single()\r\n updateState(store, 'Load Metadata - Table', { auth: { ...store.auth(), metadata: data }})\r\n } else if (rpc) {\r\n const { data } = await store.client().rpc(rpc, { input: { user_id: session?.user?.id }})\r\n updateState(store, 'Load Metadata - Rpc', { auth: { ...store.auth(), metadata: data }})\r\n } else {\r\n updateState(store, 'No Metadata', { auth: { ...store.auth(), metadata: null}})\r\n }\r\n\r\n }\r\n },\r\n\r\n })),\r\n\r\n withHooks({\r\n\r\n onInit(store) {\r\n\r\n /* Auto Load Additional User Auth Data */\r\n store._postAuth()\r\n\r\n }\r\n\r\n })\r\n\r\n)\r\n","import { inject } from '@angular/core';\r\nimport { updateState, withDevtools } from '@angular-architects/ngrx-toolkit'\r\nimport { INITIAL_STATE } from '../token/initial-state.token'\r\nimport { SupaStoreState } from '../type/supa-store.types'\r\nimport { withPostAuth } from '../features/post-auth-loader.feature'\r\nimport { signalStoreFeature, withHooks, withMethods, withProps, withState } from '@ngrx/signals'\r\nimport { toObservable } from '@angular/core/rxjs-interop'\r\nimport { filter } from 'rxjs'\r\nimport { SignInWithOAuthCredentials } from '@supabase/supabase-js'\r\nimport { WA_WINDOW, WA_SCREEN } from '@ng-web-apis/common'\r\n\r\nexport const withSupaStoreCore = () => signalStoreFeature(\r\n\r\n withDevtools('supaStore'),\r\n withState<SupaStoreState>(() => inject(INITIAL_STATE)),\r\n withPostAuth(),\r\n\r\n withProps(({ auth: { user, session, metadata }}) => ({\r\n _SCREEN: inject(WA_SCREEN),\r\n _WINDOW: inject(WA_WINDOW),\r\n user$: toObservable(user).pipe(filter(res => res !== undefined)),\r\n session$: toObservable(session).pipe(filter(res => res !== undefined)),\r\n metadata$: toObservable(metadata).pipe(filter(res => res !== undefined))\r\n })),\r\n\r\n withMethods(store => ({\r\n\r\n _initSession: async () => {\r\n const { data: { session }, error} = await store.client().auth.getSession()\r\n updateState(store, 'Initialise Session', { auth: { ...store.auth(), session }})\r\n },\r\n\r\n _initUser: async () => {\r\n const { data: { user }, error } = await store.client().auth.getUser()\r\n updateState(store, 'Initialise User', { auth: { ...store.auth(), user }})\r\n },\r\n\r\n signInWithGoogle: async (options: Pick<SignInWithOAuthCredentials, 'options'> = {}) => {\r\n const { data: { url }, error } = await store.client().auth.signInWithOAuth({ provider: 'google', ...options })\r\n const [ width, height ] = [500,600]\r\n const [ left, top ] = [(store._SCREEN.width / 2) - (width / 2), (store._SCREEN.height / 2) - (height / 2)]\r\n store._WINDOW.open(url!, '_blank', `width=${width},height=${height},left=${left},top=${top},toolbar=no,menubar=no`)\r\n }\r\n\r\n })),\r\n\r\n withHooks({\r\n\r\n onInit(store) {\r\n\r\n /* Listen For Auth State Changes */\r\n store.client().auth.onAuthStateChange(state => {\r\n updateState(store, 'Auth State Change', { auth: { ...store.auth(), state: { prev: store.auth.state.curr(), curr: state }}})\r\n })\r\n\r\n /* Init Supabase Session */\r\n store._initSession()\r\n\r\n /* Init Supabase User */\r\n store._initUser()\r\n\r\n }\r\n\r\n })\r\n\r\n)\r\n","import { signalStore } from '@ngrx/signals'\r\nimport { withSupaStoreCore } from './common/features/supa-store-core.feature'\r\n\r\nexport const SupaStore = signalStore(\r\n withSupaStoreCore()\r\n)\r\n","import { EnvironmentProviders, inject, makeEnvironmentProviders } from \"@angular/core\"\r\nimport { SupaStore } from \"./supa-store.store\"\r\nimport { SUPA_STORE_OPTIONS } from \"./common/token/supabase-credentials.token\"\r\nimport { SupaStoreOptions } from \"./common/type/supa-store.types\"\r\nimport { createInjectionToken } from 'ngxtension/create-injection-token'\r\n\r\n\r\nexport const provideSupaStore = (options: SupaStoreOptions): EnvironmentProviders => makeEnvironmentProviders([\r\n {\r\n provide: SUPA_STORE_OPTIONS,\r\n useValue: options\r\n },\r\n SupaStore\r\n])\r\n\r\n\r\nexport const [ injectSupaClient ] = createInjectionToken(() => inject(SupaStore).client)\r\nexport const [ injectSupaAuth ] = createInjectionToken(() => inject(SupaStore).auth)\r\n","/*\r\n * Public API Surface of ob-supa-store\r\n*/\r\n\r\nexport * from './lib/supa-store.store'\r\nexport * from './lib/supa-store.provider'\r\nexport * from './lib/common/features/supa-store-core.feature'\r\nexport * from './lib/common/type/supa-store.types'\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;;AAGO,MAAM,kBAAkB,GAAG,IAAI,cAAc,CAAmB,oBAAoB,CAAC;;ACErF,MAAM,aAAa,GAAG,IAAI,cAAc,CAAiB,gBAAgB,EAAE;IAChF,OAAO,EAAE,MAAK;AAEZ,QAAA,MAAM,EAAE,YAAY,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,EAAC,GAAG,MAAM,CAAC,kBAAkB,CAAC;QACzF,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC;QAE9D,OAAO;YACL,MAAM;AACN,YAAA,IAAI,EAAE;AACJ,gBAAA,OAAO,EAAE,SAAS;AAClB,gBAAA,IAAI,EAAE,SAAS;AACf,gBAAA,QAAQ,EAAE,SAAS;gBACnB,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;AAChC;SACF;;AAGJ,CAAA,CAAC;;ACbK,MAAM,YAAY,GAAG,MAAM,kBAAkB,CAElD;IACE,KAAK,EAAE,IAAI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,EAAE,mBAAmB,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG,KAAK,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,EAAC,EAAC,CAAC;AAC7H,SAAC,CAAC;;QAGF,KAAK,CAAC,YAAY,EAAE;;QAGpB,KAAK,CAAC,SAAS,EAAE;;AAIpB,CAAA,CAAC;;MC5DS,SAAS,GAAG,WAAW,CAClC,iBAAiB,EAAE;;ACGR,MAAA,gBAAgB,GAAG,CAAC,OAAyB,KAA2B,wBAAwB,CAAC;AAC5G,IAAA;AACE,QAAA,OAAO,EAAE,kBAAkB;AAC3B,QAAA,QAAQ,EAAE;AACX,KAAA;IACD;AACD,CAAA;AAGY,MAAA,CAAE,gBAAgB,CAAE,GAAG,oBAAoB,CAAC,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM;AAC1E,MAAA,CAAE,cAAc,CAAE,GAAK,oBAAoB,CAAC,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI;;ACjBrF;;AAEE;;ACFF;;AAEG;;;;"}
|
|
@@ -1,21 +1,29 @@
|
|
|
1
|
+
import { SignInWithOAuthCredentials } from '@supabase/supabase-js';
|
|
1
2
|
export declare const withSupaStoreCore: () => import("@ngrx/signals").SignalStoreFeature<import("@ngrx/signals").EmptyFeatureResult, {
|
|
2
3
|
state: {
|
|
3
4
|
client: import("@supabase/supabase-js").SupabaseClient;
|
|
4
5
|
auth: {
|
|
5
|
-
session: import("@supabase/
|
|
6
|
-
user: import("@supabase/
|
|
7
|
-
metadata:
|
|
6
|
+
session: undefined | null | import("@supabase/supabase-js").AuthSession;
|
|
7
|
+
user: undefined | null | import("@supabase/supabase-js").AuthUser;
|
|
8
|
+
metadata: undefined | null | unknown;
|
|
8
9
|
state: {
|
|
9
|
-
prev: import("@supabase/
|
|
10
|
-
curr: import("@supabase/
|
|
10
|
+
prev: import("@supabase/supabase-js").AuthChangeEvent | null;
|
|
11
|
+
curr: import("@supabase/supabase-js").AuthChangeEvent | null;
|
|
11
12
|
};
|
|
12
13
|
};
|
|
13
14
|
};
|
|
14
|
-
props: {
|
|
15
|
+
props: {
|
|
16
|
+
_SCREEN: Screen;
|
|
17
|
+
_WINDOW: Window;
|
|
18
|
+
user$: import("rxjs").Observable<import("@supabase/supabase-js").AuthUser | null>;
|
|
19
|
+
session$: import("rxjs").Observable<import("@supabase/supabase-js").AuthSession | null>;
|
|
20
|
+
metadata$: import("rxjs").Observable<{} | null>;
|
|
21
|
+
};
|
|
15
22
|
methods: {
|
|
16
23
|
[x: string]: (newName?: unknown) => unknown;
|
|
17
24
|
_postAuth: () => Promise<void>;
|
|
18
25
|
_initSession: () => Promise<void>;
|
|
19
26
|
_initUser: () => Promise<void>;
|
|
27
|
+
signInWithGoogle: (options?: Pick<SignInWithOAuthCredentials, "options">) => Promise<void>;
|
|
20
28
|
};
|
|
21
29
|
}>;
|
|
@@ -2,9 +2,9 @@ import { AuthChangeEvent, Session, SupabaseClient, SupabaseClientOptions, User }
|
|
|
2
2
|
export type SupaStoreState = {
|
|
3
3
|
client: SupabaseClient;
|
|
4
4
|
auth: {
|
|
5
|
-
session:
|
|
6
|
-
user:
|
|
7
|
-
metadata:
|
|
5
|
+
session: undefined | null | Session;
|
|
6
|
+
user: undefined | null | User;
|
|
7
|
+
metadata: undefined | null | unknown;
|
|
8
8
|
state: {
|
|
9
9
|
prev: AuthChangeEvent | null;
|
|
10
10
|
curr: AuthChangeEvent | null;
|
|
@@ -14,9 +14,9 @@ export declare const injectSupaClient: {
|
|
|
14
14
|
};
|
|
15
15
|
export declare const injectSupaAuth: {
|
|
16
16
|
(): import("@ngrx/signals").DeepSignal<{
|
|
17
|
-
session: import("@supabase/auth-js").Session
|
|
18
|
-
user: import("@supabase/auth-js").User
|
|
19
|
-
metadata:
|
|
17
|
+
session: undefined | null | import("@supabase/auth-js").Session;
|
|
18
|
+
user: undefined | null | import("@supabase/auth-js").User;
|
|
19
|
+
metadata: undefined | null | unknown;
|
|
20
20
|
state: {
|
|
21
21
|
prev: import("@supabase/auth-js").AuthChangeEvent | null;
|
|
22
22
|
curr: import("@supabase/auth-js").AuthChangeEvent | null;
|
|
@@ -27,9 +27,9 @@ export declare const injectSupaAuth: {
|
|
|
27
27
|
} & {
|
|
28
28
|
injector?: import("@angular/core").Injector;
|
|
29
29
|
}): import("@ngrx/signals").DeepSignal<{
|
|
30
|
-
session: import("@supabase/auth-js").Session
|
|
31
|
-
user: import("@supabase/auth-js").User
|
|
32
|
-
metadata:
|
|
30
|
+
session: undefined | null | import("@supabase/auth-js").Session;
|
|
31
|
+
user: undefined | null | import("@supabase/auth-js").User;
|
|
32
|
+
metadata: undefined | null | unknown;
|
|
33
33
|
state: {
|
|
34
34
|
prev: import("@supabase/auth-js").AuthChangeEvent | null;
|
|
35
35
|
curr: import("@supabase/auth-js").AuthChangeEvent | null;
|
|
@@ -38,9 +38,9 @@ export declare const injectSupaAuth: {
|
|
|
38
38
|
(injectOptions: import("@angular/core").InjectOptions & {
|
|
39
39
|
injector?: import("@angular/core").Injector;
|
|
40
40
|
}): import("@ngrx/signals").DeepSignal<{
|
|
41
|
-
session: import("@supabase/auth-js").Session
|
|
42
|
-
user: import("@supabase/auth-js").User
|
|
43
|
-
metadata:
|
|
41
|
+
session: undefined | null | import("@supabase/auth-js").Session;
|
|
42
|
+
user: undefined | null | import("@supabase/auth-js").User;
|
|
43
|
+
metadata: undefined | null | unknown;
|
|
44
44
|
state: {
|
|
45
45
|
prev: import("@supabase/auth-js").AuthChangeEvent | null;
|
|
46
46
|
curr: import("@supabase/auth-js").AuthChangeEvent | null;
|
|
@@ -2,20 +2,24 @@ export declare const SupaStore: import("@angular/core").Type<{
|
|
|
2
2
|
[x: string]: (newName?: unknown) => unknown;
|
|
3
3
|
client: import("@ngrx/signals").DeepSignal<import("@supabase/supabase-js").SupabaseClient<any, "public", any>>;
|
|
4
4
|
auth: import("@ngrx/signals").DeepSignal<{
|
|
5
|
-
session: import("@supabase/auth-js").Session
|
|
6
|
-
user: import("@supabase/auth-js").User
|
|
7
|
-
metadata:
|
|
5
|
+
session: undefined | null | import("@supabase/auth-js").Session;
|
|
6
|
+
user: undefined | null | import("@supabase/auth-js").User;
|
|
7
|
+
metadata: undefined | null | unknown;
|
|
8
8
|
state: {
|
|
9
9
|
prev: import("@supabase/auth-js").AuthChangeEvent | null;
|
|
10
10
|
curr: import("@supabase/auth-js").AuthChangeEvent | null;
|
|
11
11
|
};
|
|
12
12
|
}>;
|
|
13
|
+
user$: import("rxjs").Observable<import("@supabase/auth-js").User | null>;
|
|
14
|
+
session$: import("rxjs").Observable<import("@supabase/auth-js").Session | null>;
|
|
15
|
+
metadata$: import("rxjs").Observable<{} | null>;
|
|
16
|
+
signInWithGoogle: (options?: Pick<import("@supabase/auth-js").SignInWithOAuthCredentials, "options">) => Promise<void>;
|
|
13
17
|
} & import("@ngrx/signals").StateSource<{
|
|
14
18
|
client: import("@supabase/supabase-js").SupabaseClient;
|
|
15
19
|
auth: {
|
|
16
|
-
session: import("@supabase/auth-js").Session
|
|
17
|
-
user: import("@supabase/auth-js").User
|
|
18
|
-
metadata:
|
|
20
|
+
session: undefined | null | import("@supabase/auth-js").Session;
|
|
21
|
+
user: undefined | null | import("@supabase/auth-js").User;
|
|
22
|
+
metadata: undefined | null | unknown;
|
|
19
23
|
state: {
|
|
20
24
|
prev: import("@supabase/auth-js").AuthChangeEvent | null;
|
|
21
25
|
curr: import("@supabase/auth-js").AuthChangeEvent | null;
|