Dallas
Dallas

Reputation: 65

Client_fetch_error session ConnRefused (next-auth v3)

First I am trying to run the production build on my local machine that is why I am still using localhost:3000 for next url. I get the following error in the terminal: https://next-auth.js.org/errors#client_fetch_error session FetchError: request to http://localhost:3000/api/auth/session failed, reason: connect ECONNREFUSED ::1:3000

so it is giving me a connection refused just for the session when i run in dev mode the code works and the session is created. here is my [...nextauth].js api page.

import NextAuth from "next-auth";
import Providers from "next-auth/providers";
import { connectDatabase } from "../../../helpers/db-util";
import { verifyPasswd } from "../../../helpers/api-util";

export default NextAuth({
  session: {
    jwt: true,
  },
  providers: [
    Providers.Credentials({
      async authorize(credentials) {
        const client = await connectDatabase();

        const usersCollection = client.db().collection("members");
        
       
        const user = await usersCollection.findOne({
          memberId: credentials.memberNumber
        });
        console.log(user)
        if (!user) {
          client.close();
          throw new Error("No User Found");
        }
        const isValid = await verifyPasswd(credentials.password, user.password);

        if (!isValid) {
          client.close();
          throw new Error("Invalid Password");
        }
        client.close();
        // =================================================================
        // I might have to store the data for the token above the client.close() method
        // if so will store an object.
        //================================================================
        return {
          name: user.memberId,
          email: user.email
          
        };
      },
    }),
  ],
});

The connection to the mongo data base to look up the user works fine. could really use some help on this one.

Upvotes: 1

Views: 619

Answers (1)

justADev
justADev

Reputation: 11

To solve this issue it would help to show us your connexion database code specially url. if you have docker, you should resolve url with the name of your container. i have also a connection issue with next but during server side rendering

Upvotes: 0

Related Questions