Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Fix NO_SECRET warning thrown by Next-Auth

I have a Next js application that uses Next Auth. While in development I continuously keep getting that warning stipulating that I need to set a secret but I don't know where I should set it.

Following this reference I see I just need to run openssl rand -base64 32 to get a secret but I have no Idea where to put it

like image 948
Laspeed Avatar asked Sep 14 '25 11:09

Laspeed


2 Answers

In the [...nextauth].js outside provider and callback you can set the secret and it's value. As it is recommended to store such values in environment variable you can do the following

export default NextAuth({
 
  providers: [ 
  ],
  callbacks: {
  },
  secret: process.env.JWT_SECRET,
});
like image 76
Laspeed Avatar answered Sep 16 '25 00:09

Laspeed


You should insert the command openssl rand -base64 32in your Linux terminal, then it will generate a Token to use it on an .env file with the variable name NEXTAUTH_SECRET=token_generated. So the error [next-auth][warn][NO_SECRET] will not be showed again on console.

like image 25
maegop Avatar answered Sep 16 '25 00:09

maegop