captaincodeman / sveltekit-example Goto Github PK
View Code? Open in Web Editor NEWExample showing SvelteKit used with Firebase
Home Page: https://www.captaincodeman.com/re-creating-the-sveltekit-session-store
License: MIT License
Example showing SvelteKit used with Firebase
Home Page: https://www.captaincodeman.com/re-creating-the-sveltekit-session-store
License: MIT License
Thanks so much for this example!
I'm starting to play around with Svelte and your setup with firebase auth in a store is very helpful. However I haven't been able to set up a properly protected route. I tried setting it up in the load
function like in the real-world example, but stores aren't available in <script context="module">
s. Then I tried setting up a redirect with goto
inside onMount
but the store is always unset at the beginning, so it always ends up trying to redirect as if there was no user signed in. It isn't until after the onMount
runs that the onAuthStateChanged
in listen
kicks in and sets the auth store to the current user.
I'm wondering if I need to store the auth value in a cookie on top of the store or if there's a better, svelte-way of doing things.
Could you add an example of a protected route in this example app?
It's OK for the initial seed to set the server-rendered session state on the client, but changing auth state now means POSTing back to the server endpoint and then invalidate()
-int the page data to trigger a re-load.
It would be more efficient to return the session state as a response to the POST request, or just update it on the client with the user it already has.
The downside for the latter is that we need to deal with firebase's bat-shit-stupid ever-so-slightly different view on the shape of the User
object, and we'd loose the chance to set other session information - maybe we lookup some preferences on the server-side when a user signs-in for example.
But the POST to the server, followed by another HTTP request to re-fetch data is a bit of an abomination when it comes to "web" and doesn't really re-create the original $session
store approach that SvelteKit provided.
I tried running the repo, but got
Line must be greater than or equal to 1, got -1
TypeError: Line must be greater than or equal to 1, got -1
at BasicSourceMapConsumer.SourceMapConsumer_findMapping [as _findMapping] (/Users/.../sveltekit-example/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:65405:13)
at BasicSourceMapConsumer.SourceMapConsumer_originalPositionFor [as originalPositionFor] (/Users/.../sveltekit-example/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:65474:22)
at /Users/.../sveltekit-example/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:66413:34
at String.replace (<anonymous>)
at /Users/.../sveltekit-example/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:66403:21
at Array.map (<anonymous>)
at ssrRewriteStacktrace (/Users/.../sveltekit-example/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:66402:10)
at instantiateModule (/Users/.../sveltekit-example/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:66547:28)
I am using yarn, if that makes a difference
Do you happen to know what changed?
https://github.com/mrwokkel/sveltekit-example updates to latest versions.
A lot of [vite] Error when evaluating SSR module...
errors pop up.
When signing in, this does not actually add the user
collection or a user document in Firestore.
( I only tried in the emulator, so far )
Sveltekit has a built-in Session store. any thoughts on using that?
Thanks for bringing this project, it helps a lot.
Can you please add Phone number authentication flow with firebase.
How do you handle loading data server side and/versus handling with Firestore db in the browser?
Server side... I guess I will have to initialize the app within admin.ts and import it in +page.ts. But as long as I am in the "browser" how to I handle queries locally?
Here is my "broken" code, btw: master...fredguth:sveltekit-example:master
Hi,
thank you for this example, I have a little question,
I can't understand the need for the known property
Hi. This is almost what I was looking for. Could you please add examples for unit testing and e2e testing with the Firebase emulators.
That would be really great. I've not been able to get it working ... so far ... and since SvelteKit is pretty new, haven't found any other examples.
Hi!
I don't quite understand why there are async
/await
in some code.
For example in:
// auth.ts
async function signInWith(name: string) {
const auth = getAuth(app)
const provider = providerFor(name)
await signInWithRedirect(auth, provider)
}
async function signOut() {
const auth = getAuth(app)
await _signOut(auth)
}
What are the roles for those async
/await
?
First of all, thank you for this example! It's really helpful.
Would you mind adding a license to this project? Without one, it's not possible to legally copy any of your examples.
See Licensing a repository:
You're under no obligation to choose a license. However, without a license, the default copyright laws apply, meaning that you retain all rights to your source code and no one may reproduce, distribute, or create derivative works from your work. If you're creating an open source project, we strongly encourage you to include an open source license. The Open Source Guide provides additional guidance on choosing the correct license for your project.
See https://kit.svelte.dev/docs#configuration for an example
No "exports" main defined in /Users/nikos/WebstormProjects/sveltekit-example/node_modules/@sveltejs/adapter-node/package.json
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.