小编Cil*_*ilp的帖子

Cookie 是在开发时设置的,但不在 vercel 服务器中设置

我的应用程序由 API (nestjs) 和客户端 (nextjs) 组成。

我正在使用 getServerSideProps 来验证用户身份,并在发生错误时重定向到登录站点:

export const getServerSideProps: GetServerSideProps = async (context) => {
  try {
    // Check whether the user is logged in
    await axios.get(
      `${process.env.NEXT_PUBLIC_API}/authentication`,
      {
        withCredentials: true,
        // Cookies are attached to the request with context
        headers: context.req ? { cookie: context.req.headers?.cookie || '' } : { cookie: '' },
      },
    );

    return {
      props: {},
    };
  } catch (err) {
    return {
      redirect: {
        destination: '/login',
        permanent: false,
      },
    };
  }
}; …
Run Code Online (Sandbox Code Playgroud)

javascript authentication cookies http cross-domain

7
推荐指数
0
解决办法
456
查看次数

标签 统计

authentication ×1

cookies ×1

cross-domain ×1

http ×1

javascript ×1