Next-Auth Credential-Provider - [next-auth][error][client_fetch_error]

Viewed 2189

I want to try nextjs with next-auth for authentication with the credential provider. But i always get the following error when i'm logged in and try to open a protected route:

[next-auth][error][client_fetch_error] 
https://next-auth.js.org/errors#client_fetch_error session FetchError: invalid json response body at http://localhost:3000/api/auth/session reason: Unexpected token < in JSON at position 0
    at C:\Users\me\workspace\vscode\projects\next-auth-typescript-example\node_modules\node-fetch\lib\index.js:272:32
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:95:5) {
  type: 'invalid-json'
}

To reproduce the error you can do the following steps:

  1. Check out the official next-auth example for typescript: next-auth typescript example
  2. Follow the steps for the next-auth repository
  3. Then open the file /pages/api/auth/[...nextauth].ts
  4. Add the credentials provider with my code
  5. Start the server and try to log in trought the credentials provider with any credentials
  6. Try to open the protected route
  7. Look at your console, you will find the error

Code for the credentials provider:

Providers.Credentials({
      name: "Ogame Credentials",
      credentials: {
        username: { label: "Username", type: "text" },
        password: { label: "Password", type: "password" },
      },
      async authorize(credentials, req) {
        const user: User = {
          id: 1,
          name: "J Smith",
          email: "jsmith@example.com",
          image: "https://google.de",
        }

        if (user) {
          return user
        } else {
          return null
        }
      },
    }),

This code is from the examples from the next-auth repo too.

1 Answers

Ok, i found the problem. I installed miniconda for my python enviroment. I didn't recognized that miniconda hooks in into powershell by default (base in front of the powershell line)

So i deactivated miniconda for powershell and now it's working.

Related