svelte-firekit 0.2.2 → 0.2.3

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.
@@ -31,8 +31,8 @@
31
31
  onUnauthorized,
32
32
  fallback
33
33
  }: {
34
- /** Content shown when the auth requirement is satisfied. */
35
- children: Snippet<[UserProfile, () => Promise<void>]>;
34
+ /** Content shown when the auth requirement is satisfied. User is null when requireAuth is false. */
35
+ children: Snippet<[UserProfile | null, () => Promise<void>]>;
36
36
  /** When true (default), requires a signed-in user. When false, requires no user. */
37
37
  requireAuth?: boolean;
38
38
  /** Called when the auth state does not meet the requirement. Use for navigation. */
@@ -59,6 +59,6 @@
59
59
  {#if fallback}
60
60
  {@render fallback()}
61
61
  {/if}
62
- {:else if firekitUser.isAuthenticated === requireAuth && firekitUser.user}
62
+ {:else if firekitUser.isAuthenticated === requireAuth}
63
63
  {@render children(firekitUser.user, signOut)}
64
64
  {/if}
@@ -1,8 +1,8 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  import type { UserProfile } from '../types/auth.js';
3
3
  type $$ComponentProps = {
4
- /** Content shown when the auth requirement is satisfied. */
5
- children: Snippet<[UserProfile, () => Promise<void>]>;
4
+ /** Content shown when the auth requirement is satisfied. User is null when requireAuth is false. */
5
+ children: Snippet<[UserProfile | null, () => Promise<void>]>;
6
6
  /** When true (default), requires a signed-in user. When false, requires no user. */
7
7
  requireAuth?: boolean;
8
8
  /** Called when the auth state does not meet the requirement. Use for navigation. */
@@ -28,7 +28,7 @@
28
28
  fallback,
29
29
  verificationChecks = []
30
30
  }: {
31
- children: Snippet<[UserProfile, () => Promise<void>]>;
31
+ children: Snippet<[UserProfile | null, () => Promise<void>]>;
32
32
  requireAuth?: boolean;
33
33
  onUnauthorized?: () => void;
34
34
  fallback?: Snippet;
@@ -82,6 +82,6 @@
82
82
  {#if fallback}
83
83
  {@render fallback()}
84
84
  {/if}
85
- {:else if firekitUser.isAuthenticated === requireAuth && verificationPassed && firekitUser.user}
85
+ {:else if firekitUser.isAuthenticated === requireAuth && verificationPassed}
86
86
  {@render children(firekitUser.user, signOut)}
87
87
  {/if}
@@ -1,7 +1,7 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  import type { UserProfile } from '../types/auth.js';
3
3
  type $$ComponentProps = {
4
- children: Snippet<[UserProfile, () => Promise<void>]>;
4
+ children: Snippet<[UserProfile | null, () => Promise<void>]>;
5
5
  requireAuth?: boolean;
6
6
  onUnauthorized?: () => void;
7
7
  fallback?: Snippet;
@@ -5,18 +5,32 @@
5
5
 
6
6
  /**
7
7
  * Renders `children` only when a non-anonymous user is signed in.
8
- * Uses runes no subscription needed.
8
+ * Optionally renders a `fallback` while auth state is loading.
9
9
  *
10
10
  * @example
11
11
  * <SignedIn>
12
12
  * {#snippet children(user)}
13
13
  * <p>Hello {user.displayName}</p>
14
14
  * {/snippet}
15
+ * {#snippet fallback()}
16
+ * <p>Loading…</p>
17
+ * {/snippet}
15
18
  * </SignedIn>
16
19
  */
17
- let { children }: { children: Snippet<[UserProfile]> } = $props();
20
+ let {
21
+ children,
22
+ fallback
23
+ }: {
24
+ children: Snippet<[UserProfile]>;
25
+ /** Shown while auth state is being determined. */
26
+ fallback?: Snippet;
27
+ } = $props();
18
28
  </script>
19
29
 
20
- {#if firekitUser.isAuthenticated && firekitUser.user}
30
+ {#if firekitUser.loading}
31
+ {#if fallback}
32
+ {@render fallback()}
33
+ {/if}
34
+ {:else if firekitUser.isAuthenticated && firekitUser.user}
21
35
  {@render children(firekitUser.user)}
22
36
  {/if}
@@ -2,6 +2,8 @@ import type { Snippet } from 'svelte';
2
2
  import type { UserProfile } from '../types/auth.js';
3
3
  type $$ComponentProps = {
4
4
  children: Snippet<[UserProfile]>;
5
+ /** Shown while auth state is being determined. */
6
+ fallback?: Snippet;
5
7
  };
6
8
  declare const SignedIn: import("svelte").Component<$$ComponentProps, {}, "">;
7
9
  type SignedIn = ReturnType<typeof SignedIn>;
@@ -3,23 +3,31 @@
3
3
  import { firekitUser } from '../services/user.svelte.js';
4
4
 
5
5
  /**
6
- * Renders `children` only when no authenticated user exists (including during loading).
7
- * Passes a sign-in trigger function to children wire it up to your auth method of choice.
6
+ * Renders `children` only when no authenticated user exists.
7
+ * Waits for auth to initialize before rendering to avoid flashing
8
+ * a login form to users who are already signed in.
9
+ * Optionally renders a `fallback` while auth state is loading.
8
10
  *
9
11
  * @example
10
12
  * <SignedOut>
11
13
  * {#snippet children(signIn)}
12
14
  * <button onclick={signIn}>Sign in with Google</button>
13
15
  * {/snippet}
16
+ * {#snippet fallback()}
17
+ * <p>Checking auth…</p>
18
+ * {/snippet}
14
19
  * </SignedOut>
15
20
  */
16
21
  let {
17
22
  children,
18
- onSignIn
23
+ onSignIn,
24
+ fallback
19
25
  }: {
20
26
  children: Snippet<[() => void]>;
21
27
  /** Optional callback invoked when the user triggers sign-in from the snippet. */
22
28
  onSignIn?: () => void;
29
+ /** Shown while auth state is being determined. */
30
+ fallback?: Snippet;
23
31
  } = $props();
24
32
 
25
33
  function triggerSignIn() {
@@ -27,6 +35,10 @@
27
35
  }
28
36
  </script>
29
37
 
30
- {#if !firekitUser.isAuthenticated && !firekitUser.loading}
38
+ {#if firekitUser.loading}
39
+ {#if fallback}
40
+ {@render fallback()}
41
+ {/if}
42
+ {:else if !firekitUser.isAuthenticated}
31
43
  {@render children(triggerSignIn)}
32
44
  {/if}
@@ -3,6 +3,8 @@ type $$ComponentProps = {
3
3
  children: Snippet<[() => void]>;
4
4
  /** Optional callback invoked when the user triggers sign-in from the snippet. */
5
5
  onSignIn?: () => void;
6
+ /** Shown while auth state is being determined. */
7
+ fallback?: Snippet;
6
8
  };
7
9
  declare const SignedOut: import("svelte").Component<$$ComponentProps, {}, "">;
8
10
  type SignedOut = ReturnType<typeof SignedOut>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-firekit",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "A Svelte library for Firebase integration",
5
5
  "license": "MIT",
6
6
  "author": "Giovani Rodriguez",