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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/sveltedfire/auth/authState.d.ts +2 -0
- package/dist/sveltedfire/auth/authState.js +8 -0
- package/dist/sveltedfire/components/PromptSignIn.svelte +2 -4
- package/dist/sveltedfire/components/SignedIn.svelte +2 -5
- package/dist/sveltedfire/components/SignedOut.svelte +2 -5
- package/dist/sveltedfire/components/SveltedAuth.svelte +4 -3
- package/package.json +1 -1
- package/dist/sveltedfire/auth/getAuthContext.d.ts +0 -2
- package/dist/sveltedfire/auth/getAuthContext.js +0 -4
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
|
|
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 {
|
|
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 {
|
|
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';
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
const { children } = $props()
|
|
3
|
-
import {
|
|
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
|
|
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 {
|
|
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
|
|
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 {
|
|
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
|
-
|
|
47
|
+
authState.set(fullAuth)
|
|
47
48
|
|
|
48
49
|
</script>
|
|
49
50
|
|
package/package.json
CHANGED