@outbuild/supa-store 0.0.3 → 0.0.4

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/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@outbuild/supa-store",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "peerDependencies": {
5
5
  "@angular/common": "^18.2.0",
6
6
  "@angular/core": "^18.2.0",
7
7
  "@ngrx/signals": "^18.0.2",
8
- "@supabase/supabase-js": "^2.45.3"
8
+ "@supabase/supabase-js": "^2.45.3",
9
+ "@angular-architects/ngrx-toolkit": "18.0.3"
9
10
  },
10
11
  "dependencies": {
11
12
  "tslib": "^2.3.0"
@@ -2,10 +2,12 @@ import { EnvironmentProviders, makeEnvironmentProviders, ModuleWithProviders, Ng
2
2
  import { SupaStore } from "./supa-store.store"
3
3
  import { SUPABASE_CREDENTIALS } from "./common/token/supabase-credentials.token"
4
4
 
5
- export function provideSupaStore(supabaseUrl: string, supabaseKey: string): EnvironmentProviders { return makeEnvironmentProviders([
6
- {
7
- provide: SUPABASE_CREDENTIALS,
8
- useValue: { supabaseUrl, supabaseKey }
9
- },
10
- SupaStore
11
- ])}
5
+ export function provideSupaStore(supabaseUrl: string, supabaseKey: string): EnvironmentProviders {
6
+ return makeEnvironmentProviders([
7
+ {
8
+ provide: SUPABASE_CREDENTIALS,
9
+ useValue: { supabaseUrl, supabaseKey }
10
+ },
11
+ SupaStore
12
+ ])
13
+ }
@@ -1,4 +1,4 @@
1
- import { inject } from '@angular/core';
1
+ import { inject, InjectionToken } from '@angular/core';
2
2
  import { patchState, signalStore, signalStoreFeature, withHooks, withMethods, withState } from '@ngrx/signals';
3
3
  import { AuthChangeEvent, Session, SupabaseClient, createClient } from '@supabase/supabase-js'
4
4
  import { SUPABASE_CREDENTIALS } from './common/token/supabase-credentials.token'
@@ -9,21 +9,29 @@ export type SupaStoreState = {
9
9
  authState: AuthChangeEvent | null
10
10
  }
11
11
 
12
- function withSupaStore() {
12
+ const INITIAL_STATE = new InjectionToken<SupaStoreState>('SupaStoreState', {
13
+ factory: () => {
14
+ const { supabaseUrl, supabaseKey } = inject(SUPABASE_CREDENTIALS)
15
+ return {
16
+ client: createClient(supabaseUrl, supabaseKey),
17
+ session: undefined,
18
+ authState: null
19
+ }
20
+ },
21
+ });
13
22
 
14
- const { supabaseUrl, supabaseKey } = inject(SUPABASE_CREDENTIALS)
23
+ function withSupaStore() {
15
24
 
16
25
  return signalStoreFeature(
17
26
 
18
- withState<SupaStoreState>({
19
- client: createClient(supabaseUrl, supabaseKey),
20
- session: undefined,
21
- authState: null
22
- }),
27
+ withState<SupaStoreState>(() => inject(INITIAL_STATE)),
23
28
 
24
29
  withMethods(( store ) => ({
25
30
  initSession: async () => {
31
+ console.log('initSession')
32
+ console.log('store.client()', store.client())
26
33
  const { data: { session }} = await store.client().auth.getSession()
34
+ console.log('session', session)
27
35
  patchState(store, { session: session as Session })
28
36
  }
29
37
  })),
package/src/public-api.ts CHANGED
@@ -3,4 +3,4 @@
3
3
  */
4
4
 
5
5
  export * from './lib/supa-store.store'
6
- export * from './lib/supa-store.module'
6
+ export * from './lib/supa-store.provider'