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);
}
};