I to values stored in a writable store
import { writable } from 'svelte/store'
export const user = writable(null)
export const isLoggedIn = writable(false)
I then import these values from and set them in the index
import { getAuth, signInWithPopup, GoogleAuthProvider } from "firebase/auth";
import { user, isLoggedIn } from "../stores/authStore";
const provider = new GoogleAuthProvider();
const auth = getAuth();
function signIn() {
signInWithPopup(auth, provider)
.then((result) => {
user.set(result.user)
isLoggedIn.set(true);
console.log($isLoggedIn);
console.log($user.email);
if ($user.email.includes(".edu")) window.location.href = "/home";
else window.location.href = "/Sorry";
//sign user into db
})
.catch((error) => {
console.log("Someting wrong");
console.error(error);
});
}
When I change page and print the values again using
console.log($userValue, $isLoggedIn)
It returns the default values of
null false
I don't know if I'm using the wrong syntax or maybe I need to use cookies, but I am pretty nube at sveltekit and would love some help.