Next-Auth 部署到 AWS Amplify 在一个 Next.js 应用程序中。

huangapple go评论63阅读模式
英文:

Next-Auth deployment to aws amplify in a NextJS application

问题

I am using NextAuth for authentication using Cognito...

While adding storage (S3) I am getting this error

I tried to go to Amplify Dashboard to add storage and there

so I manually tried to reuse my auth setup but same error

I need client secret for next-auth else I need to change my whole code structure...

英文:

I am using NextAuth for authentication using Cognito...

While adding storage (S3) I am getting this error
Next-Auth 部署到 AWS Amplify 在一个 Next.js 应用程序中。

I tried to go to Amplify Dashboard to add storage and there

Next-Auth 部署到 AWS Amplify 在一个 Next.js 应用程序中。

so I manually tried to reuse my auth setup but same error

Next-Auth 部署到 AWS Amplify 在一个 Next.js 应用程序中。

I need client secret for next-auth else I need to change my whole code structure...

Next-Auth 部署到 AWS Amplify 在一个 Next.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"];
		token.id  = profile.sub;
		}
		return  token;
	},
	session({ session, token }) {
		if (session.user) {
		// modify session
		session.user.roles  = token.role;
		session.user.id  = token.id;
		}
		return  session;
		},
	},
});

Any help will be appreciated...

答案1

得分: 1

这可能与Cognito的配置问题有关,我不确定,但我附上了一个YouTube链接,以便您可以参考并重新检查Cognito的配置。
链接以供参考

英文:

I think that must related to any configuration issue with cognito, I am not sure but i am attaching a youtube link so that you can refer and recheck your configuration of cognito
link to refer

huangapple
  • 本文由 发表于 2023年5月13日 15:39:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76241599.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定