codediodeio / sveltefire

Cybernetically enhanced Firebase apps
MIT License
1.67k stars 127 forks source link

SvelteFire + SvelteKit - Using authentication&user back-end #147

Open gdrose opened 8 months ago

gdrose commented 8 months ago

We're currently developing a SvelteKit project using Firebase and we wanted to use Sveltefire as well because it's great for what we need.

The problem comes when we want to use the user in the backend (e.g.: +page.server.ts files) and for that we know we cannot import nor use the stores that sveltefire operates with. What we want to do is something like using the getFirebaseContext() (or anything actually that can give us access to that) function and retrieve the informations we need (e.g.: in the load function of a page):

export const load = async ({ locals }) => {
        const { auth } = getFirebaseContext();
        console.log('We have the user here!', auth?.currentUser);
};

How should we properly use these functions of sveltefire with SSR and sveltekit? Any feedback is appreciated :)