Next.js Discord

Discord Forum

No secret | nextAuth

Answered
Naeemgg posted this in #help-forum
Open in Discord
Avatar
import NextAuth, { AuthOptions } from "next-auth"
import CredentialsProvider from "next-auth/providers/credentials"
export const authOptions:AuthOptions = {providers: [
    CredentialsProvider({
      name: 'Credentials',
      credentials: {
        username: { label: "Username", type: "text", placeholder: "jsmith" },
        password: { label: "Password", type: "password" }
      },
      async authorize(credentials, req) {
        const res = await fetch("/api/user", {
          method: 'POST',
          body: JSON.stringify(credentials),
          headers: { "Content-Type": "application/json" }
        })
        const user = await res.json()

        if (res.status===200 && user) {
          return user
        }
        return null
      }
    })
  ],
  //secret: `lhc6tiqPum3VlZrv/BT7LRe9jHA/TGWYztBETtmj2IY=`,
  secret: process.env.NEXTAUTH_SECRET,
  
}
const handler = NextAuth(authOptions)
export { handler as GET, handler as POST }

tried both ways, directly injecting a secret in route.ts as well as optimally using NEXTAUTH_SECRET env var but still getting errors.
Image
Answered by Naeemgg
I tried and tried and ended up making another next app and migrating current one to it and everything is good now
View full answer

7 Replies

Avatar
Are u generating the secret using openssl?
Also update to the latest nextauth. I literally cannot see why this wouldnt work otherwise tbh
Avatar
Yes
And it was latest version
Avatar
I tried and tried and ended up making another next app and migrating current one to it and everything is good now
Answer
Avatar
Idk why it happened, what was it's cause
Irony is with local Dev and prod vercel logs were showing the same error