svelte-firekit 0.0.1 → 0.0.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.
Files changed (178) hide show
  1. package/README.md +82 -34
  2. package/dist/auth/reset-password.svelte +1 -1
  3. package/dist/auth/sign-in.svelte +2 -2
  4. package/dist/auth/sign-in.svelte.d.ts +1 -1
  5. package/dist/components/auth/google-sign-in.svelte +15 -1
  6. package/dist/components/auth/reset-password-form.svelte +16 -17
  7. package/dist/components/auth/sign-in-form.svelte +24 -23
  8. package/dist/components/auth/sign-up-form.svelte +52 -45
  9. package/dist/{auth → components/auth}/user-button.svelte +35 -34
  10. package/dist/{auth → components/auth}/user-button.svelte.d.ts +2 -2
  11. package/dist/components/firestore/collection.svelte +45 -0
  12. package/dist/components/firestore/collection.svelte.d.ts +25 -0
  13. package/dist/components/firestore/doc.svelte +39 -0
  14. package/dist/components/firestore/doc.svelte.d.ts +25 -0
  15. package/dist/components/nav/app-sidebar.svelte +46 -0
  16. package/dist/components/nav/app-sidebar.svelte.d.ts +8 -0
  17. package/dist/components/nav/breadcrumb.svelte +42 -0
  18. package/dist/components/nav/breadcrumb.svelte.d.ts +19 -0
  19. package/dist/components/nav/dark-mode-toggle.svelte +16 -0
  20. package/dist/components/nav/dark-mode-toggle.svelte.d.ts +18 -0
  21. package/dist/components/nav/nav.d.ts +11 -0
  22. package/dist/components/nav/nav.js +157 -0
  23. package/dist/components/nav/search-form.svelte +21 -0
  24. package/dist/components/nav/search-form.svelte.d.ts +4 -0
  25. package/dist/components/nav/version-switcher.svelte +48 -0
  26. package/dist/components/nav/version-switcher.svelte.d.ts +5 -0
  27. package/dist/components/public/footer-main.svelte +0 -0
  28. package/dist/components/public/footer-main.svelte.d.ts +26 -0
  29. package/dist/components/public/nav-main.svelte +136 -0
  30. package/dist/components/public/nav-main.svelte.d.ts +18 -0
  31. package/dist/components/storage/upload.svelte +134 -0
  32. package/dist/components/storage/upload.svelte.d.ts +11 -0
  33. package/dist/components/ui/breadcrumb/breadcrumb-ellipsis.svelte +23 -0
  34. package/dist/components/ui/breadcrumb/breadcrumb-ellipsis.svelte.d.ts +4 -0
  35. package/dist/components/ui/breadcrumb/breadcrumb-item.svelte +16 -0
  36. package/dist/components/ui/breadcrumb/breadcrumb-item.svelte.d.ts +4 -0
  37. package/dist/components/ui/breadcrumb/breadcrumb-link.svelte +31 -0
  38. package/dist/components/ui/breadcrumb/breadcrumb-link.svelte.d.ts +10 -0
  39. package/dist/components/ui/breadcrumb/breadcrumb-list.svelte +23 -0
  40. package/dist/components/ui/breadcrumb/breadcrumb-list.svelte.d.ts +4 -0
  41. package/dist/components/ui/breadcrumb/breadcrumb-page.svelte +23 -0
  42. package/dist/components/ui/breadcrumb/breadcrumb-page.svelte.d.ts +4 -0
  43. package/dist/components/ui/breadcrumb/breadcrumb-separator.svelte +27 -0
  44. package/dist/components/ui/breadcrumb/breadcrumb-separator.svelte.d.ts +4 -0
  45. package/dist/components/ui/breadcrumb/breadcrumb.svelte +15 -0
  46. package/dist/components/ui/breadcrumb/breadcrumb.svelte.d.ts +4 -0
  47. package/dist/components/ui/breadcrumb/index.d.ts +8 -0
  48. package/dist/components/ui/breadcrumb/index.js +10 -0
  49. package/dist/components/ui/dropdown-menu/dropdown-menu-checkbox-item.svelte +10 -7
  50. package/dist/components/ui/dropdown-menu/dropdown-menu-checkbox-item.svelte.d.ts +4 -3
  51. package/dist/components/ui/dropdown-menu/dropdown-menu-item.svelte.d.ts +1 -0
  52. package/dist/components/ui/input/input.svelte.d.ts +1 -1
  53. package/dist/components/ui/separator/index.d.ts +2 -0
  54. package/dist/components/ui/separator/index.js +4 -0
  55. package/dist/components/ui/separator/separator.svelte +22 -0
  56. package/dist/components/ui/separator/separator.svelte.d.ts +3 -0
  57. package/dist/components/ui/sheet/index.js +14 -0
  58. package/dist/components/ui/sheet/sheet-content.svelte +52 -0
  59. package/dist/components/ui/sheet/sheet-content.svelte.d.ts +59 -0
  60. package/dist/components/ui/sheet/sheet-description.svelte +16 -0
  61. package/dist/components/ui/sheet/sheet-description.svelte.d.ts +3 -0
  62. package/dist/components/ui/sheet/sheet-footer.svelte +20 -0
  63. package/dist/components/ui/sheet/sheet-footer.svelte.d.ts +4 -0
  64. package/dist/components/ui/sheet/sheet-header.svelte +20 -0
  65. package/dist/components/ui/sheet/sheet-header.svelte.d.ts +4 -0
  66. package/dist/components/ui/sheet/sheet-overlay.svelte +19 -0
  67. package/dist/components/ui/sheet/sheet-overlay.svelte.d.ts +3 -0
  68. package/dist/components/ui/sheet/sheet-title.svelte +16 -0
  69. package/dist/components/ui/sheet/sheet-title.svelte.d.ts +3 -0
  70. package/dist/components/ui/sidebar/constants.d.ts +6 -0
  71. package/dist/components/ui/sidebar/constants.js +6 -0
  72. package/dist/components/ui/sidebar/context.svelte.d.ts +42 -0
  73. package/dist/components/ui/sidebar/context.svelte.js +54 -0
  74. package/dist/components/ui/sidebar/index.d.ts +25 -0
  75. package/dist/components/ui/sidebar/index.js +27 -0
  76. package/dist/components/ui/sidebar/sidebar-content.svelte +24 -0
  77. package/dist/components/ui/sidebar/sidebar-content.svelte.d.ts +4 -0
  78. package/dist/components/ui/sidebar/sidebar-footer.svelte +21 -0
  79. package/dist/components/ui/sidebar/sidebar-footer.svelte.d.ts +4 -0
  80. package/dist/components/ui/sidebar/sidebar-group-action.svelte +36 -0
  81. package/dist/components/ui/sidebar/sidebar-group-action.svelte.d.ts +10 -0
  82. package/dist/components/ui/sidebar/sidebar-group-content.svelte +21 -0
  83. package/dist/components/ui/sidebar/sidebar-group-content.svelte.d.ts +4 -0
  84. package/dist/components/ui/sidebar/sidebar-group-label.svelte +34 -0
  85. package/dist/components/ui/sidebar/sidebar-group-label.svelte.d.ts +10 -0
  86. package/dist/components/ui/sidebar/sidebar-group.svelte +21 -0
  87. package/dist/components/ui/sidebar/sidebar-group.svelte.d.ts +4 -0
  88. package/dist/components/ui/sidebar/sidebar-header.svelte +21 -0
  89. package/dist/components/ui/sidebar/sidebar-header.svelte.d.ts +4 -0
  90. package/dist/components/ui/sidebar/sidebar-input.svelte +23 -0
  91. package/dist/components/ui/sidebar/sidebar-input.svelte.d.ts +4 -0
  92. package/dist/components/ui/sidebar/sidebar-inset.svelte +24 -0
  93. package/dist/components/ui/sidebar/sidebar-inset.svelte.d.ts +4 -0
  94. package/dist/components/ui/sidebar/sidebar-menu-action.svelte +43 -0
  95. package/dist/components/ui/sidebar/sidebar-menu-action.svelte.d.ts +11 -0
  96. package/dist/components/ui/sidebar/sidebar-menu-badge.svelte +29 -0
  97. package/dist/components/ui/sidebar/sidebar-menu-badge.svelte.d.ts +4 -0
  98. package/dist/components/ui/sidebar/sidebar-menu-button.svelte +97 -0
  99. package/dist/components/ui/sidebar/sidebar-menu-button.svelte.d.ts +91 -0
  100. package/dist/components/ui/sidebar/sidebar-menu-item.svelte +21 -0
  101. package/dist/components/ui/sidebar/sidebar-menu-item.svelte.d.ts +4 -0
  102. package/dist/components/ui/sidebar/sidebar-menu-skeleton.svelte +36 -0
  103. package/dist/components/ui/sidebar/sidebar-menu-skeleton.svelte.d.ts +7 -0
  104. package/dist/components/ui/sidebar/sidebar-menu-sub-button.svelte +43 -0
  105. package/dist/components/ui/sidebar/sidebar-menu-sub-button.svelte.d.ts +12 -0
  106. package/dist/components/ui/sidebar/sidebar-menu-sub-item.svelte +14 -0
  107. package/dist/components/ui/sidebar/sidebar-menu-sub-item.svelte.d.ts +4 -0
  108. package/dist/components/ui/sidebar/sidebar-menu-sub.svelte +25 -0
  109. package/dist/components/ui/sidebar/sidebar-menu-sub.svelte.d.ts +4 -0
  110. package/dist/components/ui/sidebar/sidebar-menu.svelte +21 -0
  111. package/dist/components/ui/sidebar/sidebar-menu.svelte.d.ts +4 -0
  112. package/dist/components/ui/sidebar/sidebar-provider.svelte +59 -0
  113. package/dist/components/ui/sidebar/sidebar-provider.svelte.d.ts +9 -0
  114. package/dist/components/ui/sidebar/sidebar-rail.svelte +36 -0
  115. package/dist/components/ui/sidebar/sidebar-rail.svelte.d.ts +4 -0
  116. package/dist/components/ui/sidebar/sidebar-separator.svelte +18 -0
  117. package/dist/components/ui/sidebar/sidebar-separator.svelte.d.ts +12 -0
  118. package/dist/components/ui/sidebar/sidebar-trigger.svelte +34 -0
  119. package/dist/components/ui/sidebar/sidebar-trigger.svelte.d.ts +9 -0
  120. package/dist/components/ui/sidebar/sidebar.svelte +98 -0
  121. package/dist/components/ui/sidebar/sidebar.svelte.d.ts +9 -0
  122. package/dist/components/ui/skeleton/index.d.ts +2 -0
  123. package/dist/components/ui/skeleton/index.js +4 -0
  124. package/dist/components/ui/skeleton/skeleton.svelte +17 -0
  125. package/dist/components/ui/skeleton/skeleton.svelte.d.ts +4 -0
  126. package/dist/components/ui/tooltip/index.js +8 -0
  127. package/dist/components/ui/tooltip/tooltip-content.svelte +21 -0
  128. package/dist/components/ui/tooltip/tooltip-content.svelte.d.ts +3 -0
  129. package/dist/firebase/auth/auth-guard.svelte.d.ts +25 -0
  130. package/dist/firebase/auth/auth-guard.svelte.js +79 -0
  131. package/dist/firebase/auth/auth.d.ts +21 -0
  132. package/dist/firebase/auth/auth.js +71 -0
  133. package/dist/firebase/auth/user.svelte.d.ts +50 -0
  134. package/dist/firebase/auth/user.svelte.js +115 -0
  135. package/dist/firebase/config.js +44 -0
  136. package/dist/firebase/firebase.d.ts +28 -0
  137. package/dist/firebase/firebase.js +86 -0
  138. package/dist/firebase/firestore/awaitable-doc.svelte.d.ts +15 -0
  139. package/dist/firebase/firestore/awaitable-doc.svelte.js +57 -0
  140. package/dist/firebase/firestore/collection.svelte.d.ts +17 -0
  141. package/dist/firebase/firestore/collection.svelte.js +58 -0
  142. package/dist/firebase/firestore/doc.svelte.d.ts +16 -0
  143. package/dist/firebase/firestore/doc.svelte.js +56 -0
  144. package/dist/firebase/firestore/document-mutations.svelte.d.ts +18 -0
  145. package/dist/firebase/firestore/document-mutations.svelte.js +58 -0
  146. package/dist/firebase/storage/download-url.svelte.d.ts +14 -0
  147. package/dist/firebase/storage/download-url.svelte.js +45 -0
  148. package/dist/firebase/storage/storage-list.svelte.d.ts +17 -0
  149. package/dist/firebase/storage/storage-list.svelte.js +51 -0
  150. package/dist/firebase/storage/upload-task.svelte.d.ts +22 -0
  151. package/dist/firebase/storage/upload-task.svelte.js +65 -0
  152. package/dist/hooks/is-mobile.svelte.d.ts +5 -0
  153. package/dist/hooks/is-mobile.svelte.js +23 -0
  154. package/dist/index.d.ts +22 -2
  155. package/dist/index.js +29 -3
  156. package/dist/types/docs.d.ts +50 -0
  157. package/dist/utils.d.ts +27 -1
  158. package/dist/utils.js +85 -9
  159. package/package.json +9 -7
  160. package/dist/auth/uid.js +0 -7
  161. package/dist/auth/user.svelte.d.ts +0 -10
  162. package/dist/auth/user.svelte.js +0 -21
  163. package/dist/auth.d.ts +0 -39
  164. package/dist/auth.js +0 -100
  165. package/dist/config.js +0 -39
  166. package/dist/firebase.d.ts +0 -43
  167. package/dist/firebase.js +0 -110
  168. package/dist/firestore/Collection.svelte +0 -148
  169. package/dist/firestore/Collection.svelte.d.ts +0 -27
  170. package/dist/firestore/collection.svelte.js +0 -207
  171. package/dist/firestore/doc.svelte.d.ts +0 -1
  172. package/dist/firestore/doc.svelte.js +0 -1
  173. package/dist/firestore/firestore.d.ts +0 -31
  174. package/dist/firestore/firestore.js +0 -100
  175. package/dist/firestore/perf.d.ts +0 -3
  176. package/dist/firestore/perf.js +0 -12
  177. /package/dist/{config.d.ts → firebase/config.d.ts} +0 -0
  178. /package/dist/{auth/uid.d.ts → types/docs.js} +0 -0
package/README.md CHANGED
@@ -1,58 +1,106 @@
1
- # create-svelte
1
+ # Firekit
2
2
 
3
- Everything you need to build a Svelte library, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).
3
+ Firekit is a powerful Firebase toolkit for SvelteKit applications, providing a comprehensive set of utilities, stores, and components for Firebase integration.
4
4
 
5
- Read more about creating a library [in the docs](https://svelte.dev/docs/kit/packaging).
5
+ ## Features
6
6
 
7
- ## Creating a project
7
+ - 🔥 **Firebase Integration** - Seamless Firebase setup and configuration
8
+ - 🔐 **Authentication** - Complete auth system with built-in components
9
+ - 📚 **Firestore** - Reactive data stores and CRUD operations
10
+ - 📦 **Storage** - File upload and management utilities
11
+ - 🛡️ **Route Guards** - Protected routes and authorization
12
+ - ⚡ **SSR Compatible** - Full server-side rendering support
13
+ - 🎯 **Type Safe** - Built with TypeScript for better development experience
8
14
 
9
- If you're seeing this, you've probably already done this step. Congrats!
15
+ ## Quick Start
10
16
 
11
17
  ```bash
12
- # create a new project in the current directory
13
- npx sv create
14
-
15
- # create a new project in my-app
16
- npx sv create my-app
18
+ # Install with your package manager of choice
19
+ npm install @firekit/sveltekit
20
+ pnpm install @firekit/sveltekit
21
+ yarn add @firekit/sveltekit
17
22
  ```
18
23
 
19
- ## Developing
24
+ ## Basic Usage
20
25
 
21
- Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
26
+ ```typescript
27
+ // Configure Firebase
28
+ import { firebaseConfig } from '@firekit/sveltekit';
29
+ firebaseConfig.init({
30
+ apiKey: 'your-api-key',
31
+ // ... other firebase config
32
+ });
22
33
 
23
- ```bash
24
- npm run dev
34
+ // Use Authentication
35
+ import { firekitAuth } from '@firekit/sveltekit';
36
+ await firekitAuth.signInWithEmail(email, password);
37
+
38
+ // Access User State
39
+ import { firekitUser } from '@firekit/sveltekit';
40
+ isLoggedIn = $derived(firekitUser.isLoggedIn);
41
+
42
+ // Protect Routes
43
+ import { firekitAuthGuard } from '@firekit/sveltekit';
44
+ await firekitAuthGuard.requireAuth();
25
45
 
26
- # or start the server and open the app in a new browser tab
27
- npm run dev -- --open
46
+ // Use Firestore
47
+ import { firekitDoc, firekitCollection } from '@firekit/sveltekit';
48
+ const document = firekitDoc<UserData>('users/123');
49
+ const collection = firekitCollection<PostData>('posts');
50
+
51
+ // Handle File Uploads
52
+ import { firekitUploadTask } from '@firekit/sveltekit';
53
+ const uploadTask = firekitUploadTask('path/to/file', file);
28
54
  ```
29
55
 
30
- Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.
56
+ ## Available Services
31
57
 
32
- ## Building
58
+ ### Firebase Configuration
59
+ - `firebaseConfig` - Firebase app configuration
60
+ - `firebaseService` - Core Firebase service initialization
33
61
 
34
- To build your library:
62
+ ### Authentication
63
+ - `firekitUser` - User state management
64
+ - `firekitAuth` - Authentication methods
65
+ - `firekitAuthGuard` - Route protection
35
66
 
36
- ```bash
37
- npm run package
38
- ```
67
+ ### Firestore
68
+ - `firekitDoc` - Real-time document subscription
69
+ - `firekitAwaitableDoc` - Promise-based document operations
70
+ - `firekitCollection` - Real-time collection subscription
71
+ - `firekitDocMutations` - Document CRUD operations
39
72
 
40
- To create a production version of your showcase app:
73
+ ### Storage
74
+ - `firekitDownloadUrl` - File URL management
75
+ - `firekitStorageList` - Storage browsing
76
+ - `firekitUploadTask` - File upload handling
41
77
 
42
- ```bash
43
- npm run build
44
- ```
78
+ ## Built-in Components
45
79
 
46
- You can preview the production build with `npm run preview`.
80
+ ### Authentication
81
+ - `SignInPage` - Complete sign-in page
82
+ - `SignUpPage` - User registration page
83
+ - `ResetPasswordPage` - Password reset flow
84
+ - `SignInForm` - Reusable sign-in form
85
+ - `SignUpForm` - Reusable registration form
86
+ - `ResetPasswordForm` - Password reset form
87
+ - `UserButton` - User profile button
47
88
 
48
- > To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
89
+ ### Firestore
90
+ - `Collection` - Collection data display
91
+ - `Doc` - Document data display
49
92
 
50
- ## Publishing
93
+ ### Storage
94
+ - `Upload` - File upload component
51
95
 
52
- Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)).
96
+ ## Documentation
53
97
 
54
- To publish your library to [npm](https://www.npmjs.com):
98
+ Visit our [documentation site](https://firekit.codegio.com) for detailed guides and API references.
55
99
 
56
- ```bash
57
- npm publish
58
- ```
100
+ ## Contributing
101
+
102
+ We welcome contributions! Please see our [contributing guidelines](CONTRIBUTING.md) for details.
103
+
104
+ ## License
105
+
106
+ MIT License - see [LICENSE](LICENSE) for details.
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">
2
2
  import ResetPasswordForm from "../components/auth/reset-password-form.svelte";
3
3
  import Button from "../components/ui/button/button.svelte";
4
- import * as Card from "../components/ui/card";
4
+ import * as Card from "../components/ui/card/index.js";
5
5
  </script>
6
6
 
7
7
  <Card.Root class="sm:w-[448px]">
@@ -2,8 +2,8 @@
2
2
  import SignInWithGoogle from "../components/auth/google-sign-in.svelte";
3
3
  import SignInForm from "../components/auth/sign-in-form.svelte";
4
4
  import Button from "../components/ui/button/button.svelte";
5
- import * as Card from "../components/ui/card";
6
- let { title = "Sign in" }: { title: string } = $props();
5
+ import * as Card from "../components/ui/card/index.js";
6
+ let { title = "Sign in" }: { title?: string } = $props();
7
7
  </script>
8
8
 
9
9
  <Card.Root class="sm:w-[448px]">
@@ -1,4 +1,4 @@
1
1
  declare const SignIn: import("svelte").Component<{
2
- title: string;
2
+ title?: string;
3
3
  }, {}, "">;
4
4
  export default SignIn;
@@ -1,7 +1,21 @@
1
1
  <script lang="ts">
2
- import { signInWithGoogle } from "../../auth.js";
2
+ import { firekitAuth } from "../../firebase/auth/auth.js";
3
+ import { toast } from "svelte-sonner";
4
+
3
5
  import Button from "../ui/button/button.svelte";
4
6
  let { label = "Sign in" }: { label: string } = $props();
7
+
8
+ async function signInWithGoogle() {
9
+ try {
10
+ await firekitAuth.signInWithGoogle();
11
+ } catch (error) {
12
+ if (error instanceof Error) {
13
+ toast.error(error.message);
14
+ } else {
15
+ toast.error("An error occurred");
16
+ }
17
+ }
18
+ }
5
19
  </script>
6
20
 
7
21
  <Button onclick={signInWithGoogle} class="w-full gap-2" variant="outline">
@@ -1,19 +1,15 @@
1
1
  <script lang="ts">
2
2
  import { goto } from "$app/navigation";
3
- import { sendPasswordReset } from "../../auth.js";
3
+ import { firekitAuth } from "../../firebase/auth/auth.js";
4
+
4
5
  import * as Form from "../ui/form/index.js";
5
6
  import { Input } from "../ui/input/index.js";
6
- import {
7
- resetPasswordSchema,
8
- } from "../../schemas/reset-password.js";
7
+ import { resetPasswordSchema } from "../../schemas/reset-password.js";
9
8
  import { toast } from "svelte-sonner";
10
- import {
11
- superForm,defaults
12
- } from "sveltekit-superforms";
13
- import { zodClient } from "sveltekit-superforms/adapters";
14
- import { valibot } from 'sveltekit-superforms/adapters';
9
+ import { superForm, defaults } from "sveltekit-superforms";
10
+ import { valibot } from "sveltekit-superforms/adapters";
15
11
 
16
- const data = defaults(valibot(resetPasswordSchema));
12
+ const data = defaults(valibot(resetPasswordSchema));
17
13
 
18
14
  const form = superForm(data, {
19
15
  validators: valibot(resetPasswordSchema),
@@ -26,7 +22,7 @@ const data = defaults(valibot(resetPasswordSchema));
26
22
  try {
27
23
  const { data } = form;
28
24
  const { email } = data;
29
- await sendPasswordReset(email);
25
+ await firekitAuth.sendPasswordReset(email);
30
26
  toast.success("Password reset email sent");
31
27
  goto("/sign-in");
32
28
  } catch (error) {
@@ -44,12 +40,15 @@ const data = defaults(valibot(resetPasswordSchema));
44
40
 
45
41
  <form method="POST" use:enhance class="space-y-4">
46
42
  <Form.Field {form} name="email">
47
- <Form.Control >
48
- {#snippet children({ props })}
49
- <Form.Label>Email address</Form.Label>
50
- <Input {...props} bind:value={$formData.email} placeholder="you@email.com"/>
51
- {/snippet}
52
-
43
+ <Form.Control>
44
+ {#snippet children({ props })}
45
+ <Form.Label>Email address</Form.Label>
46
+ <Input
47
+ {...props}
48
+ bind:value={$formData.email}
49
+ placeholder="you@email.com"
50
+ />
51
+ {/snippet}
53
52
  </Form.Control>
54
53
  <Form.FieldErrors />
55
54
  </Form.Field>
@@ -1,20 +1,18 @@
1
1
  <script lang="ts">
2
- import { signInWithEmail } from "../../auth.js";
2
+ import { firekitAuth } from "../../firebase/auth/auth.js";
3
3
  import { signInSchema } from "../../schemas/sign-in.js";
4
- import {
5
- superForm, defaults
6
- } from "sveltekit-superforms";
4
+ import { superForm, defaults } from "sveltekit-superforms";
7
5
  import { Input } from "../ui/input/index.js";
8
6
  import Button from "../ui/button/button.svelte";
9
- import { valibot } from 'sveltekit-superforms/adapters';
7
+ import { valibot } from "sveltekit-superforms/adapters";
10
8
 
11
- const data = defaults(valibot(signInSchema));
9
+ const data = defaults(valibot(signInSchema));
12
10
 
13
11
  import * as Form from "../ui/form/index.js";
14
12
  import { toast } from "svelte-sonner";
15
13
 
16
14
  const form = superForm(data, {
17
- validators: valibot(signInSchema),
15
+ validators: valibot(signInSchema),
18
16
  dataType: "json",
19
17
  SPA: true,
20
18
  resetForm: false,
@@ -24,7 +22,7 @@ const data = defaults(valibot(signInSchema));
24
22
  try {
25
23
  const { data } = form;
26
24
  const { email, password } = data;
27
- await signInWithEmail(email, password);
25
+ await firekitAuth.signInWithEmail(email, password);
28
26
  toast.success("Signed in successfully");
29
27
  } catch (error) {
30
28
  if (error instanceof Error) {
@@ -41,35 +39,38 @@ const data = defaults(valibot(signInSchema));
41
39
 
42
40
  <form method="POST" use:enhance class="space-y-2">
43
41
  <Form.Field {form} name="email">
44
- <Form.Control >
45
- {#snippet children({ props })}
46
- <Form.Label>Email</Form.Label>
47
- <Input {...props} bind:value={$formData.email} placeholder="you@email.com"/>
48
- {/snippet}
49
-
42
+ <Form.Control>
43
+ {#snippet children({ props })}
44
+ <Form.Label>Email</Form.Label>
45
+ <Input
46
+ {...props}
47
+ bind:value={$formData.email}
48
+ placeholder="you@email.com"
49
+ />
50
+ {/snippet}
50
51
  </Form.Control>
51
52
  <Form.FieldErrors />
52
53
  </Form.Field>
53
54
  <Form.Field {form} name="password">
54
- <Form.Control >
55
+ <Form.Control>
55
56
  {#snippet children({ props })}
56
-
57
57
  <div class="flex w-full items-center justify-between">
58
58
  <Form.Label>Password</Form.Label>
59
- <Button variant="link" class="text-sm" href="/reset-password "
60
- >
61
- I forgot my password
62
- </Button
59
+ <Button
60
+ variant="link"
61
+ class="text-sm"
62
+ href="/reset-password "
63
63
  >
64
+ I forgot my password
65
+ </Button>
64
66
  </div>
65
67
  <Input
66
- {...props}
68
+ {...props}
67
69
  bind:value={$formData.password}
68
70
  placeholder="*********"
69
71
  type="password"
70
72
  />
71
- {/snippet}
72
-
73
+ {/snippet}
73
74
  </Form.Control>
74
75
  <Form.FieldErrors />
75
76
  </Form.Field>
@@ -1,19 +1,18 @@
1
1
  <script lang="ts">
2
- import { registerWithEmail } from "../../auth.js";
2
+ import { firekitAuth } from "../../firebase/auth/auth.js";
3
+
3
4
  import * as Form from "../ui/form/index.js";
4
5
  import { Input } from "../ui/input/index.js";
5
6
  import { signUpSchema } from "../../schemas/sign-up.js";
6
7
  import { toast } from "svelte-sonner";
7
- import {
8
- superForm,defaults
9
- } from "sveltekit-superforms";
10
- import { valibot } from 'sveltekit-superforms/adapters';
11
- import Button from "../ui/button/button.svelte";
12
- import Checkbox from "../ui/checkbox/checkbox.svelte";
13
- const data = defaults(valibot(signUpSchema));
8
+ import { superForm, defaults } from "sveltekit-superforms";
9
+ import { valibot } from "sveltekit-superforms/adapters";
10
+ import Button from "../ui/button/button.svelte";
11
+ import Checkbox from "../ui/checkbox/checkbox.svelte";
12
+ const data = defaults(valibot(signUpSchema));
14
13
 
15
14
  const form = superForm(data, {
16
- validators: valibot(signUpSchema),
15
+ validators: valibot(signUpSchema),
17
16
  dataType: "json",
18
17
  SPA: true,
19
18
  resetForm: false,
@@ -24,7 +23,11 @@ const data = defaults(valibot(signUpSchema));
24
23
  const { data } = form;
25
24
  const { email, password, firstName, lastName } = data;
26
25
  const displayName = `${firstName} ${lastName}`;
27
- await registerWithEmail(email, password, displayName);
26
+ await firekitAuth.registerWithEmail(
27
+ email,
28
+ password,
29
+ displayName,
30
+ );
28
31
  toast.success("Account created successfully");
29
32
  } catch (error) {
30
33
  if (error instanceof Error) {
@@ -42,7 +45,7 @@ const data = defaults(valibot(signUpSchema));
42
45
  <form method="POST" use:enhance class="space-y-2">
43
46
  <div class="grid grid-cols-2 gap-4">
44
47
  <Form.Field {form} name="firstName">
45
- <Form.Control >
48
+ <Form.Control>
46
49
  {#snippet children({ props })}
47
50
  <Form.Label>First Name</Form.Label>
48
51
  <Input
@@ -50,60 +53,64 @@ const data = defaults(valibot(signUpSchema));
50
53
  bind:value={$formData.firstName}
51
54
  placeholder="John"
52
55
  />
53
- {/snippet}
54
-
56
+ {/snippet}
55
57
  </Form.Control>
56
58
  <Form.FieldErrors />
57
59
  </Form.Field>
58
60
  <Form.Field {form} name="lastName">
59
- <Form.Control >
60
- {#snippet children({ props })}
61
-
62
- <Form.Label>First Name</Form.Label>
63
- <Input
64
- {...props}
65
- bind:value={$formData.lastName}
66
- placeholder="Smith"
67
- />
61
+ <Form.Control>
62
+ {#snippet children({ props })}
63
+ <Form.Label>First Name</Form.Label>
64
+ <Input
65
+ {...props}
66
+ bind:value={$formData.lastName}
67
+ placeholder="Smith"
68
+ />
68
69
  {/snippet}
69
70
  </Form.Control>
70
71
  <Form.FieldErrors />
71
72
  </Form.Field>
72
73
  </div>
73
74
  <Form.Field {form} name="email">
74
- <Form.Control >
75
- {#snippet children({ props })}
76
- <Form.Label>Email</Form.Label>
77
- <Input {...props} bind:value={$formData.email} placeholder="you@email.com"/>
78
- {/snippet}
75
+ <Form.Control>
76
+ {#snippet children({ props })}
77
+ <Form.Label>Email</Form.Label>
78
+ <Input
79
+ {...props}
80
+ bind:value={$formData.email}
81
+ placeholder="you@email.com"
82
+ />
83
+ {/snippet}
79
84
  </Form.Control>
80
85
  <Form.FieldErrors />
81
86
  </Form.Field>
82
87
  <Form.Field {form} name="password">
83
- <Form.Control >
84
- {#snippet children({ props })}
85
-
86
- <Form.Label>Password</Form.Label>
87
- <Input
88
- {...props}
89
- bind:value={$formData.password}
90
- placeholder="*********"
91
- type="password"
92
- />
88
+ <Form.Control>
89
+ {#snippet children({ props })}
90
+ <Form.Label>Password</Form.Label>
91
+ <Input
92
+ {...props}
93
+ bind:value={$formData.password}
94
+ placeholder="*********"
95
+ type="password"
96
+ />
93
97
  {/snippet}
94
98
  </Form.Control>
95
99
  <Form.FieldErrors />
96
100
  </Form.Field>
97
101
  <Form.Field {form} name="agreeToTerms">
98
- <Form.Control >
99
- {#snippet children({ props })}
100
- <Checkbox {...props} bind:checked={$formData.agreeToTerms} />
101
-
102
- <Form.Label>
103
- I accept the
104
- <Button variant="link" href="/terms-and-conditions" class="p-0">Terms and Conditions</Button>
105
- </Form.Label>
102
+ <Form.Control>
103
+ {#snippet children({ props })}
104
+ <Checkbox {...props} bind:checked={$formData.agreeToTerms} />
106
105
 
106
+ <Form.Label>
107
+ I accept the
108
+ <Button
109
+ variant="link"
110
+ href="/terms-and-conditions"
111
+ class="p-0">Terms and Conditions</Button
112
+ >
113
+ </Form.Label>
107
114
  {/snippet}
108
115
  </Form.Control>
109
116
  <Form.FieldErrors />
@@ -1,27 +1,28 @@
1
1
  <script lang="ts">
2
- import * as DropdownMenu from "../components/ui/dropdown-menu/index.js";
3
- import * as Avatar from "../components/ui/avatar/index.js";
4
- import { authUser } from "./user.svelte.js";
5
- import { getInitials } from "../utils.js";
2
+ import * as DropdownMenu from "../ui/dropdown-menu/index.js";
3
+ import * as Avatar from "../ui/avatar/index.js";
4
+ import { getInitials } from "../../utils.js";
5
+ import type { NavItem } from "../../types/nav.js";
6
+ let { nav }: { nav?: NavItem[] } = $props();
7
+ import * as AlertDialog from "../ui/alert-dialog/index.js";
8
+ import Button from "../ui/button/button.svelte";
9
+ import { firekitUser } from "../../firebase/auth/user.svelte.js";
10
+ import { firekitAuth } from "../../firebase/auth/auth.js";
6
11
  import { LogOut } from "lucide-svelte";
7
- import { logOut } from "../auth.js";
8
- import type { NavItem } from "../types/nav.js";
9
- let { nav }: { nav: NavItem[] } = $props();
10
- import * as AlertDialog from "../components/ui/alert-dialog/index.js";
11
- import Button from "../components/ui/button/button.svelte";
12
12
  let isOpen = $state(false);
13
+
14
+ async function handleLogout() {
15
+ await firekitAuth.logOut();
16
+ }
13
17
  </script>
14
18
 
15
- {#if authUser.currentUser}
19
+ {#if firekitUser.user}
16
20
  <DropdownMenu.Root>
17
21
  <DropdownMenu.Trigger>
18
22
  <Avatar.Root>
19
- <Avatar.Image
20
- src={authUser.currentUser?.photoURL}
21
- alt="Avatar"
22
- />
23
+ <Avatar.Image src={firekitUser.photoURL} alt="Avatar" />
23
24
  <Avatar.Fallback>
24
- {getInitials(authUser.currentUser?.displayName)}
25
+ {getInitials(firekitUser.displayName)}
25
26
  </Avatar.Fallback>
26
27
  </Avatar.Root>
27
28
  </DropdownMenu.Trigger>
@@ -31,21 +32,21 @@
31
32
  <div class="flex items-center gap-3">
32
33
  <Avatar.Root>
33
34
  <Avatar.Image
34
- src={authUser.currentUser?.photoURL}
35
+ src={firekitUser.photoURL}
35
36
  alt="Avatar"
36
37
  />
37
38
  <Avatar.Fallback>
38
- {getInitials(authUser.currentUser?.displayName)}
39
+ {getInitials(firekitUser.displayName)}
39
40
  </Avatar.Fallback>
40
41
  </Avatar.Root>
41
42
  <div class="grow">
42
43
  <span
43
44
  class="block font-medium text-sm text-gray-800 dark:text-neutral-200"
44
45
  >
45
- {authUser.currentUser?.displayName}
46
+ {firekitUser.displayName}
46
47
  </span>
47
48
  <p class="text-xs text-foreground-500">
48
- {authUser.currentUser?.email}
49
+ {firekitUser.email}
49
50
  </p>
50
51
  </div>
51
52
  </div>
@@ -54,16 +55,18 @@
54
55
  <DropdownMenu.Item onclick={() => (isOpen = true)}>
55
56
  Profile
56
57
  </DropdownMenu.Item>
57
- {#each nav as { href, label }}
58
- <DropdownMenu.Item>
59
- <a {href}>
60
- {label}
61
- </a>
62
- </DropdownMenu.Item>
63
- {/each}
58
+ {#if nav}
59
+ {#each nav as { href, label }}
60
+ <DropdownMenu.Item>
61
+ <a {href}>
62
+ {label}
63
+ </a>
64
+ </DropdownMenu.Item>
65
+ {/each}
66
+ {/if}
64
67
 
65
68
  <DropdownMenu.Separator />
66
- <DropdownMenu.Item onclick={logOut}>
69
+ <DropdownMenu.Item onclick={handleLogout}>
67
70
  <LogOut /> Logout
68
71
  </DropdownMenu.Item>
69
72
  </DropdownMenu.Group>
@@ -77,27 +80,25 @@
77
80
  <div class="flex items-center gap-3">
78
81
  <Avatar.Root>
79
82
  <Avatar.Image
80
- src={authUser.currentUser?.photoURL}
83
+ src={firekitUser.photoURL}
81
84
  alt="Avatar"
82
85
  />
83
86
  <Avatar.Fallback>
84
- {getInitials(
85
- authUser.currentUser?.displayName,
86
- )}
87
+ {getInitials(firekitUser.displayName)}
87
88
  </Avatar.Fallback>
88
89
  </Avatar.Root>
89
90
  <div class="grow">
90
91
  <span
91
92
  class="block font-medium text-sm text-gray-800 dark:text-neutral-200"
92
93
  >
93
- {authUser.currentUser?.displayName}
94
+ {firekitUser.displayName}
94
95
  </span>
95
96
  <p class="text-xs text-foreground-500">
96
- {authUser.currentUser?.email}
97
+ {firekitUser.email}
97
98
  </p>
98
99
  </div>
99
100
  </div>
100
- <Button onclick={logOut} variant="link">
101
+ <Button onclick={handleLogout} variant="link">
101
102
  <LogOut />Logout
102
103
  </Button>
103
104
  </div>
@@ -1,5 +1,5 @@
1
- import type { NavItem } from "../types/nav.js";
1
+ import type { NavItem } from "../../types/nav.js";
2
2
  declare const UserButton: import("svelte").Component<{
3
- nav: NavItem[];
3
+ nav?: NavItem[];
4
4
  }, {}, "">;
5
5
  export default UserButton;