简体   繁体   English

AWS Amplify 上的 Next-AUTH UNTRUST_HOST_ERROR

[英]Next-AUTH UNTRUST_HOST_ERROR on AWS Amplify

Deployed NextJS app on AWS Amplify在 AWS Amplify 上部署 NextJS 应用程序

I am getting untrust host in my CloudWatch logs.我的 CloudWatch 日志中出现不信任主机。

Can someone help?有人可以帮忙吗?

[next-auth][error][UNTRUST_HOST_ERROR] [下一个授权][错误][UNTRUST_HOST_ERROR] 在此处输入图像描述

URL: https://master.dtzbr8sfj0q7k.amplifyapp.com/ URL: https://master.dtzbr8sfj0q7k.amplifyapp.com/

在此处输入图像描述

I have added this domain in my Cognito allowed callbacks.我已将此域添加到我的 Cognito 允许的回调中。

在此处输入图像描述

package.json package.json

"next": "13.0.7",
"next-auth": "^4.18.6",

Build Settings构建设置

version: 1
applications:
  - frontend:
      phases:
        preBuild:
          commands:
            - npm ci
        build:
          commands:
            - npm run build
            - COGNITO_CLIENT_ID=${COGNITO_CLIENT_ID}
            - COGNITO_CLIENT_SECRET=${COGNITO_CLIENT_SECRET}
            - COGNITO_DOMAIN=${COGNITO_DOMAIN}
            - JWT_SECRET=${JWT_SECRET}
            - NEXTAUTH_URL=${NEXTAUTH_URL}
      artifacts:
        baseDirectory: .next
        files:
          - '**/*'
      cache:
        paths:
          - node_modules/**/*
    appRoot: client

/pages/api/[...nextauth].js /pages/api/[...nextauth].js

import NextAuth from "next-auth/next";

function CognitoProvider(options) {
  return {
    id: "cognito",
    name: "Cognito",
    type: "oauth",
    wellKnown: `${options.issuer}/.well-known/openid-configuration`,
    idToken: true,
    profile(profile) {
      return {
        id: profile.sub,
        name: profile.name,
        email: profile.email,
        image: profile.picture,
      };
    },
    options,
  };
}

export default NextAuth({
  providers: [
    CognitoProvider({
      clientId: process.env.COGNITO_CLIENT_ID,
      clientSecret: process.env.COGNITO_CLIENT_SECRET,
      issuer: process.env.COGNITO_DOMAIN,
    }),
  ],
  secret: process.env.JWT_SECRET,
  callbacks: {
    jwt({ token, account, profile }) {
      if (account) {
        console.log("Account exists");
        // modify token
        token.role = profile["cognito:groups"];
      }
      return token;
    },

    session({ session, token }) {
      if (session.user) {
        // modify session
        session.user.roles = token.role;
      }
      return session;
    },
  },
});

/index.js /index.js

import Head from "next/head";
import App from "../components/App/App";
import { useSession, signIn, signOut } from "next-auth/react";

export default function Home() {
  const { data: session } = useSession();
  if (session) {
    return (
      <>
        <Head>
          <title>Create Next App</title>
          <meta name="description" content="Generated by create next app" />
          <meta name="viewport" content="width=device-width, initial-scale=1" />
          <link rel="icon" href="/favicon.ico" />
        </Head>
        <App />
      </>
    );
  }
  return (
    <>
      Not signed in <br />
      <button
        onClick={() => {
          e.preventDefault();
          signIn("cognito", {
            callbackUrl: process.env.NEXTAUTH_URL,
          });
        }}
      >
        Sign in
      </button>
    </>
  );
}

Any Help would be appreciated任何帮助,将不胜感激

Make sure you have configured NEXTAUTH_URL environment variable correctly on AWS Amplify.确保您已在 AWS Amplify 上正确配置NEXTAUTH_URL环境变量。

I checked your website, and I see this error:我检查了你的网站,我看到了这个错误: 错误截图

CLIENT_FETCH_ERROR CLIENT_FETCH_ERROR

On NextAuth.js documentation,在 NextAuth.js 文档中, NextAuth 文档


Here's a similar case: How to solve client fetch error for next-auth authentication这是一个类似的案例: How to solve client fetch error for next-auth authentication

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Nextauth 部署在 AWS Amplify [next-auth][error][CLIENT_FETCH_ERROR] - Nextauth deployed on AWS Amplify [next-auth][error][CLIENT_FETCH_ERROR] Next-auth、MongoDB 和 AWS SES 无法正常工作 - Next-auth, MongoDB and AWS SES not working properly 具有 firebase 身份验证的 Next-Auth - Next-Auth with firebase Authentication 在 AWS Amplify 上部署 Next.js 时出错 - Error on deploying Next.js on AWS Amplify AWS Amplify Auth - 获取已登录用户的用户属性时出错 - AWS Amplify Auth - Error when fetching user attributes of a signed in user 无法删除 AWS Amplify Auth - Can not remove AWS Amplify Auth 如何解决此连接 GRPC Stream 错误,同时尝试使用 Next-Auth 和 Firebase-Adapter 实现身份验证 - How to solve this Connection GRPC Stream Error while trying to implement Authenticaton using Next-Auth with Firebase-Adapter AWS Amplify Google 身份验证用户未重定向回 - AWS Amplify Google auth user not redirected back 在 NextJS 中使用 next-auth 添加基于角色的身份验证 - Add role based authentication using next-auth in NextJS 无法在 AWS amplify 上部署 Next Js SSR 应用程序。 (网站内部错误和部署在 cli 上失败) - Unable to Deploy Next Js SSR app on AWS amplify. ( Internal error on Website and Deployment failed on cli)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM