4 ms·
So I’m fairly new to the world of full stack web development. I’ve been trying to make an MVP using SvelteKit and Firebase, but what I’m running into is that th
by imnnos 4y ago
So I’m fairly new to the world of full stack web development. I’ve been trying to make an MVP using SvelteKit and Firebase, but what I’m running into is that they both kind of try and avoid a separate backend in different ways that seem to sometimes conflict with each other.
For instance, Firebase is meant to connect on the client so you don’t need the backend database connection, but then you can’t use SvelteKit’s SSR. Does Supabase work similarly in this aspect? What do you do in this situation?
- dimmke 4y agoThe DB connection to Supabase can be made where ever you want it to be. It’s just JavaScript. In Node, a “module” is generally scoped to a file. So you make a db.ts file and export the instance you create and it functions basically as a singleton. One DB connection per user per session. SvelteKit let’s you choose where to put that. The first place you import it is when it instantiates. Auth in SvelteKit is trickier than it should be, but there’s a really good technique that I recommend you follow: https://www.captaincodeman.com/re-creating-the-sveltekit-session-store https://www.captaincodeman.com/re-creating-the-sveltekit-ses... I believe he uses firebase in his example. But don’t just copy paste, try to understand what is actually happening and why he had to do this workaround. Once you understand how SSR actually works, things get a lot easier. Stores are a way of storing state on the client side, but to do SSR Svelte has to use stores on its “backend”. The key thing to understand is that stores that are used for SSR are server wide and persistent so you can’t store user specific data in them. There’s a special spot for that kind of state called events.locals. It’s probably the trickiest area of SvelteKit IMO. I hope they make it better.