I'm new to SvelteKit and want to make sure I'm not missing something obvious. Where is the best place to store auth status so I can grant/block access to parts of my app efficiently -- using Firebase Auth?
Right now I'm storing it in a writable store. Like so:
import { writable } from 'svelte/store'
import type firebase from 'firebase/auth'
const authStore = writable<{
isLoggedIn: boolean,
user?: firebase.UserInfo
}>({
isLoggedIn: false
})
And then in __layout.svelte I use it like so:
onMount(() => {
onAuthStateChanged(auth, (user) => {
authStore.set({
isLoggedIn: user != null,
user
})
})
})
I should add, I use the static adapter as all my "server" side code will be in Firebase Cloud Functions and won't be using endpoints.
But occasionally during dev I run into SSR issues... I'm not sure if I can (or should) be using context="module" over onMount, etc.
The Svelte and SvelteKit docs are amazing but don't delve into scenarios -- like best practices of maintaining auth across pages, etc.
That aside, so far SvelteKit + Firebase has been a fantastic platform to work in.