Error Message: An issue has occurred with the server. The resolver function is not working properly in conjunction with the next

https://i.stack.imgur.com/9vt70.jpg

Encountering an error when trying to access my login page. Using the t3 stack with next auth and here is my [...nextauth].ts file

export const authOptions: NextAuthOptions = {
  // Include user.id on session
  callbacks: {
    session({ session, user }) {
      if (session.user) {
        session.user.id = user.id;
      }
      return session;
    },
  },
  // Configure one or more authentication providers
  adapter: PrismaAdapter(prisma),
  providers: [
    GoogleProvider({
      clientId: env.GOOGLE_CLIENT_ID,
      clientSecret: env.GOOGLE_CLIENT_SECRET,
    }),
    DiscordProvider({
      clientId: env.DISCORD_CLIENT_ID,
      clientSecret: env.DISCORD_CLIENT_SECRET,
    }),
    /**
     * ...add more providers here
     *
     * Most other providers require a bit more work than the Discord provider.
     * For example, the GitHub provider requires you to add the
     * `refresh_token_expires_in` field to the Account model. Refer to the
     * NextAuth.js docs for the provider you want to use. Example:
     * @see https://next-auth.js.org/providers/github
     */
  ],
  pages: {
    signIn: "/auth/signin",
  },
};

Showcasing the button that initiates the sign-in flow as per documentation guidelines

<ul>
... other buttons ...
  <li>
    <button onClick={() => {
      session ? signOut() : signIn()
    }} className="bla bla bla"/>
  </li>
</ul>

Also sharing the structure of the sign-in page

const SignIn: NextPage<{ providers: AppProps }> = ({ providers }) => {
    return (
        <>
            <main className="h-screen">
                <div className="container h-full px-6 py-24">
                    <div
                        className="g-6 flex h-full flex-wrap items-center justify-center lg:justify-between">
                        <div className="md:w-8/12 lg:ml-6 lg:w-5/12">
                            <form>
                                <div className="relative mb-6" data-te-input-wrapper-init>
                                    <input
                                        type="text"
                                        className="bla bla bla"
                                        id="exampleFormControlInput3"
                                        placeholder="Email address" />
                                    <label
                                        htmlFor="exampleFormControlInput3"
                                        className="bla bla bla"
                                    >Email address
                                    </label>
                                </div>
                                <div className="mb-6 flex items-center justify-between">
                                    <div className="bla bla bla">
                                        <input
                                            className="bla bla bla"
                                            type="checkbox"
                                            value=""
                                            id="exampleCheck3"
                                            checked />
                                        <label
                                            className="bla bla bla"
                                            htmlFor="checkBox">
                                            Remember me
                                        </label>

                                        <button
                                            type="submit"
                                            className="bla bla bla"
                                            data-te-ripple-init
                                            data-te-ripple-color="light">
                                            Send sign-in email link
                                        </button>

                                        <div
                                            className="bla bla bla">
                                            <p
                                                className="bla bla bla">
                                                OR
                                            </p>
                                        </div>

                                        <div>
                                            {Object.values(providers).map((provider) => (
                                                <button
                                                    data-te-ripple-init
                                                    data-te-ripple-color="light"
                                                    className="bla bla bla"
                                                    style={{ backgroundColor: "#3b5998" }}
                                                    key={provider.id}
                                                    onClick={() => signIn(provider.name, {
                                                        callbackUrl: `${window.location.origin}`
                                                    })}>
                                                    Sign in with {provider.name}
                                                </button>
                                            ))}
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </main>
        </>
    );
};

export default SignIn;

export const getServerSideProps: GetServerSideProps = async () => {
    const providers = await getProviders();
    return {
        props: { providers },
    };
};

If you have any insights or advice, it would be greatly appreciated. Thank you!

Answer №1

I managed to resolve the issue by switching from const export to default export. Make sure that the file is located at: pages/api/auth/[...nextauth].ts In your situation, it should look something like this:

export default NextAuth({
    callbacks: {
      session({ session, user }) {
        if (session.user) {
          session.user.id = user.id;
        }
        return session;
      },
    },
    // Set up one or more authentication providers
    adapter: PrismaAdapter(prisma),
    providers: [
      GoogleProvider({
        clientId: env.GOOGLE_CLIENT_ID,
        clientSecret: env.GOOGLE_CLIENT_SECRET,
      }),
      DiscordProvider({
        clientId: env.DISCORD_CLIENT_ID,
        clientSecret: env.DISCORD_CLIENT_SECRET,
      }),
      /**
       * ... add more providers here
       *
       * Most other providers require additional setup compared to the Discord provider.
       * For instance, the GitHub provider needs you to include the
       * `refresh_token_expires_in` field in the Account model. Consult the
       * documentation for the specific provider you wish to use on NextAuth.js website. Example:
       * @see https://next-auth.js.org/providers/github
       */
    ],
    pages: {
      signIn: '/auth/signin',
    },
  });

I hope this information proves useful!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Getting permission for geoLocation service on iOS in Ionic: A step-by-step guide

I have recently developed a social media application that utilizes geoLocation services. The app is built with Ionic 4 and has a Firebase backend. While the GeoLocation services are functioning properly on Android devices, users of iOS are not being prompt ...

Issue with the useSWR hook causing the DOM not to update correctly due to mutation

My next.js app is utilizing the `useSWR` hook to fetch and populate data. const { data, error } = useSWR('/api/digest', fetcher, { revalidateOnFocus: false, }) The problem I am facing is that the DOM is not updating as expected after the `mu ...

choose a distinct value for every record in the table

My goal is to only change the admin status for the selected row, as shown in the images and code snippets below. When selecting 'in-progress' for the first row, I want it to update only that row's status without affecting the others. <td ...

Improper utilization of the property

I am encountering an issue where setAnimals is not recognized as a function. I have checked all the props but can't seem to locate the error Code from Form: export default function AddAnimalForm({setAnimals, animals}) { const [submitMessage, setSub ...

Enhancing Web Service Calls with Angular 2 - The Power of Chaining

I am currently facing an issue where I need to make multiple web service calls in a sequence, but the problem is that the second call is being made before the .subscribe function of the first call executes. This is causing delays in setting the value of th ...

Move forward state using navigateByUrl in Angular

I am looking to send data when changing the view using navigateByUrl like this: this.router.navigateByUrl(url, {state: {hello: "world"}}); Once in the next view, my goal is to simply log the hello attribute like so: constructor(public router: Router) { ...

The ng2-chart library displays date in the form of a Unix timestamp

I have a date object imported from my database, but it is showing up as a Unix timestamp (-62101391858000). I know I can format the date using pipes like {{myDate | date:medium}}, however, I am using ng2-charts so I need to find a different solution. My ch ...

getting TypeScript configured with webpack

I am currently using Typescript to develop a back-end API utilizing graphql and express. To manage the project development and building process, I have implemented webpack. As part of my setup, I am employing raw-loader in order to load graphql schemas an ...

Having trouble locating the name WebGLObject in my TypeScript code

Every time I try to run ng serve command An error pops up on my screen saying: "WebGLObject cannot be found." ...

Next.js encountered a surprising conclusion to the JSON input

After retrieving data from /api/notes/1, the following JSON object is received: { "id":1, "author":1, "title":"First Note", "excerpt":"Just a note, blah blah blah", "body":"First no ...

Unable to retrieve shared schema from a different schema.graphql file within the context of schema stitching

In my project, I have a user schema defined in a file named userSchema.graphql; id: String! userName: String! email: String! password: String! } In addition to the user schema, I also have separate schema files for login and register functionalit ...

Guide on integrating web-tree-sitter into a NextJS application

I am eager to create ASTs by parsing code entered on my NextJS web application. After researching, it seems that leveraging web-tree-sitter is the way to go. Following the instructions, I managed to utilize Docker to produce the tree-sitter-javascript.was ...

Error in TypeScript when utilizing an Enum as a string

Attempting to include a string enum in my Angular 2 project resulted in an error during the npm project startup: ERROR in e:/projects/dbtool-fullstack/dbtool-client/src/app/shared/models/full-m odels/enums/Sex.ts (2,10): Type '"Male"' is not ass ...

Using TypeScript for Type Inference in Fetch Operations

I created a custom Fetch wrapper in Typescript to fetch data from my API. I am facing an issue where the retrieved data is of type "any" and I want to convert it to a specific type, like "user". Here is the link to my codesandbox for reference: https://co ...

There appears to be an issue with the compilation of the TypeScript "import { myVar }" syntax in a Node/CommonJS/ES5 application

In my Node application, I have a configuration file that exports some settings as an object like this: // config.js export var config = { serverPort: 8080 } Within another module, I import these settings and try to access the serverPort property: // ...

Struggling to connect the array of objects from the .ts file with the template (.html) in Angular

Inside this .ts file, I am populating the "mesMenus" array that I want to display in the .html file: export class MenusComponent{ mesMenus= new Array<Menu>(); constructor(private gMenuService:GestionMenuService){ this.gMenuService.onAdd ...

Issue locating name (generics) in Angular 4

I'm encountering issues with Angular 4. The TypeScript code is not compiling and generating errors when I try to run ng serve. I'm getting two errors in my-data.service.ts file - "Cannot find name 'Category' at line 9, column 30" and ...

Ways to merge values across multiple arrays

There is a method to retrieve all unique properties from an array, demonstrated by the following code: var people = [{ "name": "John", "age": 30 }, { "name": "Anna", "job": true }, { "name": "Peter", "age": 35 }]; var result = []; people. ...

Tips for achieving successful return on a Post API request to MongoDB using NodeJS

As someone who is new to working with APIs for fetching and posting data, I'm struggling with figuring out how to handle actions once my Post request has been completed. I have a function in place that calls the API with the necessary Post data. The ...

Ways to display "No records" message when the filter in the material table in Angular returns no results

How can I implement a "No Records Message" for when the current table is displaying empty data? Check out this link for examples of material tables in AngularJS: https://material.angular.io/components/table/examples ...