小编Sam*_*uel的帖子

NextAuth 会话回调未触发

Nextjs通过 AWS Amplify 部署了一个 (v13) 应用程序并使用NextAuth(v4.17.0)。我正在使用CredentialsProvider自定义服务器。在开发环境中一切都很好,但在生产中,session即使在数据库中创建了令牌,回调也不会触发并且会话为空

/page/api/auth/[...nextauth].tsx 忽略控制台日志哈哈

import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import jwt_decode from "jwt-decode";
import { TokenInfo } from "../../../components/types/auth_types";


async function refreshAccessToken(token) {
    try {
        console.log("BUT WHY?");

        const res = await fetch(
            `${process.env.NEXT_PUBLIC_API_URL}/api/token/refresh/`,
            {
                method: "POST",
                body: JSON.stringify({refresh: token.refreshToken}),
                headers: {"Content-Type": "application/json"},
            }
        );

        if (!res.ok) throw "refreshError";
        const responseJson = await res.json();
        return {
            ...token,
            accessToken: responseJson.access,
        }

    } catch(error) {
        return {
            ...token, …
Run Code Online (Sandbox Code Playgroud)

next.js aws-amplify next-auth

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

标签 统计

aws-amplify ×1

next-auth ×1

next.js ×1