小编Dan*_*ita的帖子

可写存储在页面更改时被覆盖,SvelteKit

I 存储在可写存储中的值

import { writable } from 'svelte/store'

export const user = writable(null)
export const isLoggedIn = writable(false)

Run Code Online (Sandbox Code Playgroud)

然后我导入这些值并将它们设置在索引中

 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);
      });
  }
Run Code Online (Sandbox Code Playgroud)

当我更改页面并使用再次打印值时

console.log($userValue, $isLoggedIn) …
Run Code Online (Sandbox Code Playgroud)

store writable typescript sveltekit

2
推荐指数
1
解决办法
1330
查看次数

标签 统计

store ×1

sveltekit ×1

typescript ×1

writable ×1