1
1
<script lang =" ts" >
2
- import Doc from ' $lib/components/Doc.svelte' ;
3
- // import { collectionStore, docStore, userStore } from '$lib/stores';
4
- import User from ' $lib/components/User.svelte' ;
5
- import { db as firestore , auth } from ' ./firebase.js' ;
6
- import { signInAnonymously , signOut } from " firebase/auth" ;
7
- import { addDoc , collection , Firestore , orderBy , query , refEqual , where } from ' firebase/firestore' ;
8
- import Collection from ' $lib/components/Collection.svelte' ;
9
- import FirebaseApp from ' $lib/components/FirebaseApp.svelte' ;
10
- import SignedIn from ' $lib/components/SignedIn.svelte' ;
11
- import SignedOut from ' $lib/components/SignedOut.svelte' ;
12
- import { collectionStore , docStore , userDataStore } from ' $lib/stores/firestore.js' ;
13
- import { userStore } from ' $lib/stores/auth.js' ;
2
+ import { getFirebaseContext } from " $lib/stores/sdk.js" ;
14
3
15
- async function addPost(uid : string ) {
16
- const posts = collection (firestore , ` users/${uid }/posts ` );
17
- await addDoc (posts , {
18
- content: (Math .random () + 1 ).toString (36 ).substring (7 ),
19
- created: Date .now (),
20
- });
21
- }
22
-
23
- $ : makeQuery = (uid : string ) => {
24
- const q = query (collection (firestore , ` users/${uid }/posts ` ), orderBy (' created' , ' desc' ));
25
- return q ;
26
- }
27
-
28
- // const userData = userDataStore<any>();
29
- // const userQuery= userQueryStore('posts');
30
-
31
- const myUser = userStore ();
32
- const userData = docStore <{ name: string }>(' users/Toy8wnsp9AMLdxtP8cR7idM8J263' );
33
- const users = collectionStore <any >(' users' );
34
4
5
+ const ctx = getFirebaseContext ();
35
6
36
7
</script >
37
8
38
9
<h1 >Welcome to SvelteFire</h1 >
39
10
40
- <SignedIn let:user let:signOut >
41
- <p >Hi {user .displayName }</p >
42
- <button on:click ={signOut }>Sign Out</button >
43
- </SignedIn >
44
-
45
- <SignedOut >
46
- <button on:click ={() => signInAnonymously (auth )}>Sign in</button >
47
- </SignedOut >
48
-
49
-
50
-
51
- <Doc ref ="posts/first-post" startWith ={{ content : ' sup' }} let:data ={post }>
52
- <p >{post ?.content }</p >
53
- <div slot =" loading" >
54
- <p >Loading...</p >
55
- </div >
56
- </Doc >
57
-
58
- <User let:user >
59
-
60
- <p >Hello {user ?.uid }</p >
61
-
62
- <Doc ref ="posts/first-post" let:data ={post }>
63
- <p >{post ?.content }</p >
64
- <div slot =" loading" >
65
- <p >Loading...</p >
66
- </div >
67
- </Doc >
68
-
69
- <h1 >Your Posts</h1 >
70
-
71
- <Collection ref ={makeQuery (user .uid )} startWith ={[]} let:data ={posts } let:count >
72
-
73
- <p >You've made {count } posts</p >
74
-
75
- <ul >
76
- {#each posts as post (post .id )}
77
- <li >{post ?.content } ... { post .id }</li >
78
- {/each }
79
- </ul >
80
-
81
- <button on:click ={() => addPost (user .uid )}>Add Post</button >
82
- </Collection >
83
-
84
-
85
- <div slot =" signedOut" >
86
- <p >Sign in to do stuff</p >
87
- <button on:click ={() => signInAnonymously (auth )}>Sign in</button >
88
- </div >
89
- </User >
90
-
91
- <p >
92
- <a href =" /ssr" >SSR Test</a >
93
- </p >
94
-
95
- <h1 >User Query</h1 >
96
-
97
- {$myUser ?.uid }
98
-
99
- <!-- {#each $userQuery as post (post.id)}
100
- <li>{post?.content} ... { post.id }</li>
101
- {/each} -->
102
-
103
- {$userData ?.name }
104
-
105
- {#each $users as user (user .id )}
106
- <li >{user ?.name } ... { user .id }</li >
107
- {/each }
11
+ <ul >
12
+ <li ><a href =" /auth-test" >Auth Test</a ></li >
13
+ <li ><a href =" /firestore-test" >Firestore Test</a ></li >
14
+ <li ><a href =" /ssr-test" >SSR Test</a ></li >
15
+ </ul >
16
+ <ul >
17
+ <li data-testid ="auth" >Auth Context: {!! ctx .auth }</li >
18
+ <li data-testid ="firestore" >Firestore Context: {!! ctx .firestore }</li >
19
+ </ul >
0 commit comments