Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Firebase auth currentUser is always null

$
0
0

I am trying to protect a route in web app using load function ,reading the value of currentUser from auth to see if the user is logged in but it is always null. So when I refresh the page I am kicked out.

import { auth } from "$lib/firebase";import { redirect } from "@sveltejs/kit";export const load = async () => {    const user = auth.currentUser;    if (!user) {        throw redirect(302, '/login');    }    return {};};

I tried:

  1. to use onAuthStateChanged instead and implement a listener.
  2. to stop firebase from reinitialize in refreshes.
  3. implement a function with await to see if there is delay on vale update.
  4. Enforcing firebase persistence mode.
  5. It's a +page.ts. And I tried changing the values of ssd and csr as well to know how rendering affect this.

The result was always the same. null as currentUser.


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>