When working with Typescript, NextAuth throws errors while embedding

When attempting to implement NextAuth into my Typescript application, I encounter two errors: one with NextAuth and the other with NextAuthOptions.

import NextAuth from "next-auth"
import { NextAuthOptions } from "next-auth"
import GoogleProvider from "next-auth/providers/google";

export const authOptions: NextAuthOptions = ({
 providers: [
    GoogleProvider({
      clientId: `${process.env.GOOGLE_CLIENT_ID}`,
      clientSecret: `${process.env.GOOGLE_CLIENT_SECRET}`, 
    })
  ]
})

const handler = NextAuth(authOptions)
export { handler as GET, handler as POST }

The error "Module '"next-auth"' has no exported member 'NextAuthOptions'.ts(2305)" is displayed.

Additionally, the error "This expression is not callable. Type 'typeof import("next-auth")' has no call signatures." appears.

Answer №1

Include the specified types/**/*.ts in your tsconfig.json configuration:

{ 
  .
  .
  .
  "include": ["next-env.d.ts", "types/**/*.ts", "**/*.ts", "**/*.tsx"],
  .
  .
  .
}

Next, insert the following code snippet into next-auth.d.ts file:

import NextAuth, { DefaultSession } from "next-auth";

    // This is an example of module augmentation
    declare module "next-auth" {
      interface Session {
        user: {
          id: string;
        } & DefaultSession["user"];
      }
    }

Answer №3

    import FacebookAuth, { AuthConfig } from "facebook-auth";
    import TwitterProvider from "facebook-auth/providers/twitter";

    const authConfig: AuthConfig = {
     providers: [
      TwitterProvider({
      apiKey: String(process.env.TWITTER_API_KEY),
      apiSecret: String(process.env.TWITTER_API_SECRET),
      }),
     ],
    };

  export default FacebookAuth(authConfig);

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

Translation with React-i18next will occur once the component has been re-rendered

I have a webpage that supports both English and French languages using Next.js and react-i18next. The issue I am facing is that when I set the language to French (Frn) and refresh the page, it still displays English content. I noticed two peculiar things ...

How can I implement a feature in Angular where clicking the edit button loads a form (in a separate component) pre-populated with previous data, along with an update button for

Within the employee-list component, there is a table displaying a list of employees. This table includes an option to edit details. <button type="button" class="btn btn-primary" routerLink="../create-employee">Edit</b ...

Utilizing interface in NestJS for validating incoming request parameters

My goal is to utilize the interface provided by class-validator in order to validate a specific field in the incoming request body. Here's the interface structure: export enum Fields { Full_Stack_Dev = 'full stack dev', Frontend_Dev = &a ...

I am encountering an issue where I am using Getserversideprops within a page to retrieve data from Strapi, but I am consistently

Having an issue with fetching data from a Strapi backend using getServerSideProps in Next.js. The data appears to be undefined, even though the link works correctly in the browser. I am fetching inside a page, not a component, following the method descri ...

Creating a Typescript interface for a sophisticated response fetched from a REST API

I'm currently struggling with how to manage the response from VSTS API in typescript. Is there a way to handle this interface effectively? export interface Fields { 'System.AreaPath': any; 'System.TeamProject': string; 'Sys ...

Tips for utilizing withNavigation from react-navigation in a TypeScript environment

Currently, I am working on building an app using react-native, react-navigation, and typescript. The app consists of only two screens - HomeScreen and ConfigScreen, along with one component named GoToConfigButton. Here is the code for both screens: HomeSc ...

Attempting to fetch data using the useEffect hook and context API

I am working on displaying state information within a component. Utilizing context to retrieve data from various sources. const router = useRouter() const [sidebarOpen, setSidebarOpen] = useState(false) const [loadUser, setLoadUser] = useState({}) ...

React and Next.js issues with "Window is not defined" errors

Currently working with React Hooks and NextJS, I am in the process of creating a Navbar along with its functionality. However, upon refreshing the page, an error appears that was not present when I was using this code in my previous React project. If anyo ...

Display a loading splash screen prior to loading Next.js

I am working on a NextJS website and I'm looking to incorporate a Splash Screen that displays before the site is fully loaded. However, since the Splash Screen is included in the NextJS code, it ends up loading after NextJS has rendered on the server ...

The file or directory npx-cli.js cannot be found in the specified location: ../npm/bin/

Problem Description After creating a new React project using the command below, npx create-react-app my-app --template typescript and utilizing node version v18.15.0, I attempted to set up Prettier for the project following the instructions in the Pretti ...

Moving SVG Module

My goal is to create a custom component that can dynamically load and display the content of an SVG file in its template. So far, I have attempted the following approach: icon.component.ts ... @Component({ selector: 'app-icon', templa ...

Error with declaring TypeScript class due to private variable

When defining a TypeScript class like this: export class myClass { constructor(public aVariable: number) {} private aPrivateVariable: number; } and trying to initialize it with the following code: let someVar: myClass[] = [{ aVariable: 3 }, { aV ...

Creating Child Components in Vue Using Typescript

After using Vue for some time, I decided to transition to implementing Typescript. However, I've encountered an issue where accessing the child's methods through the parent's refs is causing problems. Parent Code: <template> <re ...

The issue with viewing next/image properly only occurs on desktops using a responsive layout. I would like for the image

<Image src={APIImagePath} alt={t("common:tokens")} layout="fill" className={styles.img} /> Showing on a desktop screen: https://i.stack.imgur.com/gT2ZF.png Viewing on a tablet: https://i.stack.imgur.com/yeABR.png ...

An error occurred with useState and localStorage: the parameter type 'string null' cannot be assigned to a parameter of type 'string'

I am currently using NextJS and attempting to persist a state using localStorage. Here is my code implementation: const [reportFavorite, setReportFavorite] = useState([ 'captura', 'software', 'upload', ] as any) ...

Struggling to locate the module in React Native with TypeScript configuration

Currently, I am in the middle of transitioning our react-native project from JavaScript to TypeScript. As I attempt to import old modules, I keep encountering the following error: Cannot find module 'numeral' Oddly enough, the 'numeral&apo ...

What is the significance of having both nulls in vue's ref<HTMLButtonElement | null>(null)?

Can you explain the significance of these null values in a vue ref? const submitButton = ref<HTMLButtonElement | null>(null); ...

Is there a way to remove an event listener once the associated button has been clicked within the given code?

Is there a way to prevent this event from triggering once the "dispensed" button is clicked in another module? Here is the code snippet: stopDrugOrder(e: Event, drugOrder: any, drugName: string) { const confirmDialog = this.dialog.open(SharedConfirmat ...

The AngularJS Service fails to properly convert incoming Json Responses into Model objects during piping

I have been studying AngularJS 17 and recently developed a login application. However, I am facing an issue where the server response is not being properly mapped to the object in the Model Class. Response: { "id": 1, "userName& ...

Whenever I attempt to run 'npm run build', I consistently encounter an error

I'm currently in the process of creating a website using React and Next.js. All my files are uploaded to a hosting platform, and I've successfully connected to it via SSH. However, when attempting to run the command 'npm run build', I e ...