Next.js Discord

Discord Forum

TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received an inst

Unanswered
Tibetan Terrier posted this in #help-forum
Open in Discord
Tibetan TerrierOP
I randomly get this error while using NextAuth. The OAuth flow with google does not show up.

declare module "next-auth" {
  interface Session extends DefaultSession {
    user: {
      id: string;
      // ...other properties
      // role: UserRole;
    } & DefaultSession["user"];
  }
}

/**
 * Options for NextAuth.js used to configure
 * adapters, providers, callbacks, etc.
 * @see https://next-auth.js.org/configuration/options
 **/

const allowedEmails = [""]
export const authOptions: NextAuthOptions = {
  session: {
    strategy: "jwt",
  },
  secret: process.env.NEXTAUTH_SECRET,
  callbacks: {
    session: ({session, token}) => {
      return {
        ...session,
        user: {
          ...session.user,
          id: token.id,
          randomKey: token.randomKey
        }
      }
    },
    jwt: ({token, user}) => {
      if (user) {
        const u = user as unknown as any
        return {
          ...token,
          id: u.id,
          randomKey: u.randomKey
        }
      }
      return token
    },
    async signIn({user, account, profile, email, credentials}) {
      console.log({user})
      if (!user.email) return false
      return allowedEmails.includes(user.email);
    },
  },
  adapter: PrismaAdapter(db),
  pages: {
    signIn: '/sign-in',
    error: '/sign-in-error'

  },
  providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_CLIENT_ID ?? "",
      clientSecret: process.env.GOOGLE_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
     **/
  ],

};

0 Replies