svelte-firekit 0.0.13 → 0.0.14

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.
@@ -0,0 +1,52 @@
1
+ <script lang="ts">
2
+ import type { DocumentData } from "firebase/firestore";
3
+ import { firekitAuthManager } from "../firebase/auth/auth-manager.svelte.js";
4
+
5
+ interface Props {
6
+ redirectTo?: string;
7
+ redirectParams?: Record<string, string>;
8
+ requiredClaims?: string[];
9
+ requiredData?: (data: DocumentData | null) => boolean;
10
+ allowIf?: (manager: typeof firekitAuthManager) => boolean;
11
+ children: () => any;
12
+ }
13
+
14
+ let {
15
+ redirectTo = "/login",
16
+ redirectParams,
17
+ requiredClaims = [],
18
+ requiredData,
19
+ allowIf,
20
+ children,
21
+ }: Props = $props();
22
+
23
+ let isAuthorized = $state(false);
24
+ let isValidating = $state(true);
25
+
26
+ async function validateAccess() {
27
+ isValidating = true;
28
+ isAuthorized = await firekitAuthManager.validateAuth({
29
+ authRequired: true,
30
+ redirectTo,
31
+ redirectParams,
32
+ requiredClaims,
33
+ requiredData,
34
+ allowIf,
35
+ });
36
+ isValidating = false;
37
+ }
38
+
39
+ $effect(() => {
40
+ if (firekitAuthManager.initialized) {
41
+ validateAccess();
42
+ }
43
+ });
44
+ </script>
45
+
46
+ {#if isValidating || firekitAuthManager.loading}
47
+ <div class="flex items-center justify-center p-4">
48
+ <span class="text-gray-500">Loading...</span>
49
+ </div>
50
+ {:else if isAuthorized}
51
+ {@render children()}
52
+ {/if}
@@ -0,0 +1,11 @@
1
+ import type { DocumentData } from "firebase/firestore";
2
+ import { firekitAuthManager } from "../firebase/auth/auth-manager.svelte.js";
3
+ declare const RequireAuth: import("svelte").Component<{
4
+ redirectTo?: string;
5
+ redirectParams?: Record<string, string>;
6
+ requiredClaims?: string[];
7
+ requiredData?: (data: DocumentData | null) => boolean;
8
+ allowIf?: (manager: typeof firekitAuthManager) => boolean;
9
+ children: () => any;
10
+ }, {}, "">;
11
+ export default RequireAuth;
@@ -0,0 +1,42 @@
1
+ <script lang="ts">
2
+ import { firekitAuthManager } from "../firebase/auth/auth-manager.svelte.js";
3
+
4
+ interface Props {
5
+ redirectTo?: string;
6
+ redirectParams?: Record<string, string>;
7
+ children: () => any;
8
+ }
9
+
10
+ let {
11
+ redirectTo = "/dashboard",
12
+ redirectParams,
13
+ children,
14
+ }: Props = $props();
15
+
16
+ let isAuthorized = $state(false);
17
+ let isValidating = $state(true);
18
+
19
+ async function validateAccess() {
20
+ isValidating = true;
21
+ isAuthorized = await firekitAuthManager.validateAuth({
22
+ authRequired: false,
23
+ redirectTo,
24
+ redirectParams,
25
+ });
26
+ isValidating = false;
27
+ }
28
+
29
+ $effect(() => {
30
+ if (firekitAuthManager.initialized) {
31
+ validateAccess();
32
+ }
33
+ });
34
+ </script>
35
+
36
+ {#if isValidating || firekitAuthManager.loading}
37
+ <div class="flex items-center justify-center p-4">
38
+ <span class="text-gray-500">Loading...</span>
39
+ </div>
40
+ {:else if isAuthorized}
41
+ {@render children()}
42
+ {/if}
@@ -0,0 +1,6 @@
1
+ declare const RequireNoAuth: import("svelte").Component<{
2
+ redirectTo?: string;
3
+ redirectParams?: Record<string, string>;
4
+ children: () => any;
5
+ }, {}, "">;
6
+ export default RequireNoAuth;
@@ -61,7 +61,7 @@ export declare class FirekitAuthManager {
61
61
  private generateDeviceId;
62
62
  private getPlatformInfo;
63
63
  private validateClaims;
64
- private handleRedirect;
64
+ handleRedirect(redirectTo: string, params?: Record<string, string>): Promise<void>;
65
65
  validateAuth({ authRequired, redirectTo, requiredClaims, requiredData, allowIf, redirectParams, }?: GuardConfig): Promise<boolean>;
66
66
  updateEmailUser(email: string): Promise<void>;
67
67
  updatePassword(password: string): Promise<void>;
@@ -76,8 +76,6 @@ export declare class FirekitAuthManager {
76
76
  hasRequiredClaims(requiredClaims: string[]): boolean;
77
77
  isAdmin(): boolean;
78
78
  isPremium(): boolean;
79
- requireAuth(redirectTo?: string, redirectParams?: Record<string, string>): Promise<boolean>;
80
- requireNoAuth(redirectTo?: string, redirectParams?: Record<string, string>): Promise<boolean>;
81
79
  requireClaims(claims: string[], redirectTo?: string, redirectParams?: Record<string, string>): Promise<boolean>;
82
80
  requireData(validator: (data: DocumentData | null) => boolean, redirectTo?: string, redirectParams?: Record<string, string>): Promise<boolean>;
83
81
  logOut(): Promise<void>;
@@ -353,21 +353,6 @@ export class FirekitAuthManager {
353
353
  isPremium() {
354
354
  return Boolean(this._claims.premium);
355
355
  }
356
- // Convenience methods for route guards
357
- async requireAuth(redirectTo = "/login", redirectParams) {
358
- return this.validateAuth({
359
- authRequired: true,
360
- redirectTo,
361
- redirectParams,
362
- });
363
- }
364
- async requireNoAuth(redirectTo = "/dashboard", redirectParams) {
365
- return this.validateAuth({
366
- authRequired: false,
367
- redirectTo,
368
- redirectParams,
369
- });
370
- }
371
356
  async requireClaims(claims, redirectTo = "/login", redirectParams) {
372
357
  return this.validateAuth({
373
358
  requiredClaims: claims,
package/dist/index.d.ts CHANGED
@@ -12,6 +12,8 @@ export { default as SignInPage } from './auth/sign-in.svelte';
12
12
  export { default as SignUpPage } from './auth/sign-up.svelte';
13
13
  export { default as ResetPassWordPage } from './auth/reset-password.svelte';
14
14
  export { default as AuthPage } from './auth/auth.svelte';
15
+ export { default as RequireAuth } from './auth/require-auth.svelte';
16
+ export { default as RequireNoAuth } from './auth/require-no-auth.svelte';
15
17
  export { default as ResetPassWordForm } from './components/auth/reset-password-form.svelte';
16
18
  export { default as SignInForm } from './components/auth/sign-in-form.svelte';
17
19
  export { default as SignUpForm } from './components/auth/sign-up-form.svelte';
package/dist/index.js CHANGED
@@ -19,6 +19,8 @@ export { default as SignInPage } from './auth/sign-in.svelte';
19
19
  export { default as SignUpPage } from './auth/sign-up.svelte';
20
20
  export { default as ResetPassWordPage } from './auth/reset-password.svelte';
21
21
  export { default as AuthPage } from './auth/auth.svelte';
22
+ export { default as RequireAuth } from './auth/require-auth.svelte';
23
+ export { default as RequireNoAuth } from './auth/require-no-auth.svelte';
22
24
  export { default as ResetPassWordForm } from './components/auth/reset-password-form.svelte';
23
25
  export { default as SignInForm } from './components/auth/sign-in-form.svelte';
24
26
  export { default as SignUpForm } from './components/auth/sign-up-form.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-firekit",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "dev": "vite dev",