English 中文(简体)
How to Pass Data from SvelteKit Hook to page
原标题:How to Pass Data from SvelteKit Hook to page

Im公司与SvelteKit公司合作,通过JWT在服务器栏目中进行用户认证。 我成功地将用户数据储存在会议User,在Ilog事件现场即可看到。 然而,在我的+page.svelte档案中,Im在负荷功能中很难获得这一数据。 每当我把这一数据登录在网页上时,数据就被重新确定。 正确方向的任何要点都会受到赞赏。

console log for event.locals.user { user: { id: 1 , email: [email protected] } }

缩略语

     const sessionUser: SessionUser = {
        id: decoded.sub, 
        email: decoded.email, 
      };

      (event.locals as any).user = sessionUser; 
      console.log("event.locals", event.locals);

    } catch (error) {
      console.error("JWT verification error:", error);
      (event.locals as any).user = null; 
    }
  } else {
    (event.locals as any).user = null;
  }

  return await resolve(event);
};

+page.svelt

   export const load: Load = ({ session }) => {
    const user = session.user;

    if (user) {
      let login = true;
    } else {
      let login = false;
    }

  };
问题回答

上查阅,即load上<+page.server.js。





相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Remotely authenticating client Windows user on demand

Suppose I am writing a server for a particular network protocol. If I know that the client is running on a Windows machine, is it possible for my server to authenticate the Windows user that owns the ...

Role/Permission based forms authorizing/authentication?

While looking into forms authorizing/authentication, I found that it is possible to do role based authorizing by adding an array of roles to a FormsAuthenticationTicket. That way I can write User....

热门标签