I need to retrieve values from AWS Secrets Manager
and integrate them into the authOptions configuration for next-auth
. The code implementation I have is as follows:
export const buildAuthOptions = async () => {
const secrets: AuthSecrets = await getSecret(
'secret_name',
);
return {
providers: [
CognitoProvider({
clientId: secrets.cognitoClientId,
clientSecret: secrets.cognitoClientSecret,
issuer: secrets.cognitoDomain,
}),
],
secret: secrets.JWTSecret,
};
};
export const authOptions: NextAuthOptions = buildAuthOptions();
const handler: NextAuthOptions = NextAuth(authOptions);
export { handler as GET, handler as POST };
The error displayed in the console is:
- error TypeError: options.providers is not iterable
How can I properly handle returning authOptions from an asynchronous function?