title: How to implement credentials authorization in Next.js with next-auth?
body: <p>I try to get credentials auth with <a href="https://next-auth.js.org/providers/credentials" rel="nofollow noreferrer">next-auth</a>, but I have no experience to use it and whatever I do, i get following message:</p>
  <blockquote>
  <p>[next-auth][error][callback_credentials_jwt_error] Signin in with credentials is only supported if JSON Web Tokens are enabled
  https://next-auth.js.org/errors#callback_credentials_jwt_error</p>
  </blockquote>
  <p>This is my <code>src/pages/api/auth/[...nextauth].js</code> file.</p>
  <pre class="lang-js prettyprint-override"><code>import NextAuth from 'next-auth'
  import Providers from 'next-auth/providers'
  import User from &quot;@models/User&quot;
  
  const options = {
      NEXTAUTH_URL:process.env.NEXTAUTH_URL,
      providers: [
          Providers.Credentials({
              // The name to display on the sign in form (e.g. 'Sign in with...')
              name: 'Avista',
              // The credentials is used to generate a suitable form on the sign in page.
              // You can specify whatever fields you are expecting to be submitted.
              // e.g. domain, username, password, 2FA token, etc.
  
              credentials: {
                  email: {label: &quot;Email&quot;, type: &quot;text&quot;},
                  password: {label: &quot;Password&quot;, type: &quot;password&quot;}
              },
  
              authorize: async (credentials) =&gt; {
                  // Add logic here to look up the user from the credentials supplied
                  // const user = {id: 1, name: 'J Smith', email: 'jsmith@example.com'}
                  const user = await User.findOne()
                  console.log(&quot;Данные входа&quot;, credentials)
  
                  if (user) {
                      // Any object returned will be saved in `user` property of the JWT
                      return Promise.resolve(user)
                  } else {
                      // If you return null or false then the credentials will be rejected
                      return Promise.resolve(null)
                      // You can also Reject this callback with an Error or with a URL:
                      // return Promise.reject(new Error('error message')) // Redirect to error page
                      // return Promise.reject('/path/to/redirect')        // Redirect to a URL
                  }
              }
          }),
          Providers.Email({
              server: {
                  host: process.env.EMAIL_SERVER_HOST,
                  port: process.env.EMAIL_SERVER_PORT,
                  auth: {
                      user: process.env.EMAIL_SERVER_USER,
                      pass: process.env.EMAIL_SERVER_PASSWORD
                  }
              },
              from: process.env.EMAIL_FROM
          }),
      ],
  
      // A database is optional, but required to persist accounts in a database
      database: process.env.MONGO_URI,
      secret: process.env.JWT_SIGNING_PRIVATE_KEY,
      },
  }
  </code></pre>
  <p>I don't know what I do wrong.</p>