sveltedfire 0.1.17 → 0.1.18

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 CHANGED
@@ -26,7 +26,7 @@ This guarantees that firebase has been initialized prior to any data loading cal
26
26
 
27
27
  ### Authentication
28
28
 
29
- In order to fully utilize the helper components sveltedfire contains, you must wrap your app at a high level with the `SveltedAuth` component. This initializes the firebase authentication system and provides a context that provides access to the current user. To access the auth context, use the `getAuthContext` helper. Additional keys can be injected onto the context by adding them as props on `SveltedAuth` with the prefix `extra_` and the value being a function that accepts user and token. This function will be called with user and token of null in the case of a logged out user to initialize default values. E.g., to add the key `claimLevel` to the sveltedAuth context:
29
+ In order to fully utilize the helper components sveltedfire contains, you must wrap your app at a high level with the `SveltedAuth` component. This initializes the firebase authentication system and provides a writable store that provides access to the current user. To access the auth information, use the `authState` helper with rune syntax. Additional keys can be injected onto the context by adding them as props on `SveltedAuth` with the prefix `extra_` and the value being a function that accepts user and token. This function will be called with user and token of null in the case of a logged out user to initialize default values. E.g., to add the key `claimLevel` to the sveltedAuth context:
30
30
 
31
31
  ```svelte
32
32
  <script lang="ts">
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export { listenDocs } from './sveltedfire/utilities/listenDocs.js';
8
8
  export { kindlyFetchDoc } from './sveltedfire/utilities/kindlyFetchDoc.js';
9
9
  export { kindlyFetchDocs } from './sveltedfire/utilities/kindlyFetchDocs.js';
10
10
  export { type AuthSig } from './sveltedfire/auth/AuthSig.js';
11
- export { getAuthContext } from './sveltedfire/auth/getAuthContext.js';
11
+ export { authState } from './sveltedfire/auth/authState.js';
12
12
  export { handleForm } from './sveltedfire/utilities/handleForm.js';
13
13
  import SignedIn from './sveltedfire/components/SignedIn.svelte';
14
14
  import SignedOut from './sveltedfire/components/SignedOut.svelte';
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ export { listenDocs } from './sveltedfire/utilities/listenDocs.js';
9
9
  export { kindlyFetchDoc } from './sveltedfire/utilities/kindlyFetchDoc.js';
10
10
  export { kindlyFetchDocs } from './sveltedfire/utilities/kindlyFetchDocs.js';
11
11
  export {} from './sveltedfire/auth/AuthSig.js';
12
- export { getAuthContext } from './sveltedfire/auth/getAuthContext.js';
12
+ export { authState } from './sveltedfire/auth/authState.js';
13
13
  export { handleForm } from './sveltedfire/utilities/handleForm.js';
14
14
  import SignedIn from './sveltedfire/components/SignedIn.svelte';
15
15
  import SignedOut from './sveltedfire/components/SignedOut.svelte';
@@ -0,0 +1,2 @@
1
+ import { type AuthSig } from './AuthSig.js';
2
+ export declare const authState: import("svelte/store").Writable<AuthSig>;
@@ -0,0 +1,8 @@
1
+ import { writable } from "svelte/store";
2
+ import {} from './AuthSig.js';
3
+ export const authState = writable({
4
+ currentUser: null,
5
+ signInWithGoogle: null,
6
+ signOut: null,
7
+ initialized: false
8
+ });
@@ -1,7 +1,5 @@
1
1
  <script lang="ts">
2
- import { type AuthSig, getAuthContext } from "sveltedfire";
2
+ import { authState } from "../auth/authState.js";
3
3
 
4
- const { signInWithGoogle } = getAuthContext()
5
-
6
- signInWithGoogle()
4
+ $authState.signInWithGoogle()
7
5
  </script>
@@ -1,11 +1,8 @@
1
1
  <script lang="ts">
2
2
  const { children } = $props()
3
- import { getContext } from 'svelte';
4
- import { type AuthSig } from '../auth/AuthSig.js';
5
-
6
- let fullAuth = getContext<AuthSig>('sveltedAuth')
3
+ import { authState } from '../auth/authState.js';
7
4
  </script>
8
5
 
9
- {#if fullAuth.initialized && fullAuth!.currentUser}
6
+ {#if $authState.initialized && $authState!.currentUser}
10
7
  {@render children()}
11
8
  {/if}
@@ -1,11 +1,8 @@
1
1
  <script lang="ts">
2
2
  const { children } = $props()
3
- import { getContext } from 'svelte';
4
- import { type AuthSig } from '../auth/AuthSig.js';
5
-
6
- let fullAuth = getContext<AuthSig>('sveltedAuth')
3
+ import { authState } from '../auth/authState.js';
7
4
  </script>
8
5
 
9
- {#if fullAuth && fullAuth.initialized && !fullAuth!.currentUser}
6
+ {#if $authState && $authState.initialized && !$authState!.currentUser}
10
7
  {@render children()}
11
8
  {/if}
@@ -1,10 +1,9 @@
1
1
  <script lang="ts">
2
- import { setContext } from 'svelte'
3
2
  import { getAuth, type User } from 'firebase/auth'
4
3
  import { signOut } from '../auth/signOut.js'
5
4
  import { signInWithGoogle } from '../auth/signInWithGoogle.js'
6
5
  import { type AuthSig } from '../auth/AuthSig.js';
7
- import { AUTH_CONTEXT_NAME } from '../constants.js'
6
+ import { authState } from '../auth/authState.js'
8
7
 
9
8
  const { children, ...rest } = $props()
10
9
 
@@ -28,6 +27,7 @@
28
27
  auth.authStateReady().then(() => {
29
28
  console.log('Received authStateReady')
30
29
  fullAuth.initialized = true
30
+ authState.set(fullAuth)
31
31
  })
32
32
 
33
33
  auth.onAuthStateChanged(user => {
@@ -41,9 +41,10 @@
41
41
  fullAuth[k] = rest[additionalKeys[k]](user, token)
42
42
  })
43
43
  })
44
+ authState.set(fullAuth)
44
45
  })
45
46
 
46
- setContext<AuthSig>(AUTH_CONTEXT_NAME, fullAuth)
47
+ authState.set(fullAuth)
47
48
 
48
49
  </script>
49
50
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sveltedfire",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run prepack",
@@ -1,2 +0,0 @@
1
- import { type AuthSig } from "./AuthSig.js";
2
- export declare const getAuthContext: () => AuthSig;
@@ -1,4 +0,0 @@
1
- import { getContext } from "svelte";
2
- import { AUTH_CONTEXT_NAME } from '../constants.js';
3
- import {} from "./AuthSig.js";
4
- export const getAuthContext = () => getContext(AUTH_CONTEXT_NAME);