如何解决Next Auth getSession API 调用在生产中的 getServerSideProps 函数中使用时失败
getSession
在客户端工作正常,但在服务器端不正常
当它在服务器端被调用时,我在服务器上收到此错误:
error -> https://next-auth.js.org/errors#client_fetch_error session FetchError:请求 https://nextauth_url_internal/api/auth/session 失败,原因:getaddrinfo ENOTFOUND nextauth_url_internal
服务端代码
export const getServerSideProps = async (context) => {
const { req } = context;
try {
const session = await getSession({ req });
console.log({ session });
if (!session) return { redirect: { destination: '/',permanent: false } };
return { props: { session } };
} catch (error) {
console.log(error);
}
};
解决方法
您似乎没有配置 NEXTAUTH_URL environment variable。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。