Giter Site home page Giter Site logo

captaincodeman / sveltekit-example Goto Github PK

View Code? Open in Web Editor NEW
156.0 14.0 23.0 236 KB

Example showing SvelteKit used with Firebase

Home Page: https://www.captaincodeman.com/re-creating-the-sveltekit-session-store

License: MIT License

HTML 2.39% Svelte 9.94% TypeScript 78.30% JavaScript 6.53% Shell 2.83%
firebase firebase-auth firebase-authentication session ssr svelte sveltekit

sveltekit-example's People

Contributors

captaincodeman avatar faustodc avatar hunkim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sveltekit-example's Issues

Add a protected route

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?

Don't use LayoutData / invalidate() for session updates

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.

Not working on deplying with vercel

So i added the vercel-adapter and deployed it and i get error on /session (internal error)
image

nothing more, can't figure out whats happening

Line must be greater than or equal to 1, got -1

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

No actually updating Firestore

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 )

session

Sveltekit has a built-in Session store. any thoughts on using that?

Testing

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.

Why await Firebase?

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?

Error when app is launched

Hi and thanks a lot for this example, it helps a lot.

I'm getting window is not defined ReferenceError when the app is first launched with npm run dev, both in the terminal and the browser. However, after refreshing the app it loads as expected:

image

Any idea what is causing this error?

Add license

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.