Usage of NextAuth.js in current site

I want to add NextAuth.js into my current site. Do I just copy the nextauth.js repo and add stuff over? i am using next.js in my project and all sites are made in .js.

Some questions
all the example pages are in typescript. do I need to convert?
do i move my project to the nextauth.js repo or the other way around. which is easier?
what do i need to look out for?

No, you don’t need to convert your JavaScript project to TypeScript to use NextAuth.js. The examples in the NextAuth.js documentation are in TypeScript because it provides better type safety and autocompletion, but NextAuth.js works perfectly fine with JavaScript.

You don’t need to move your project to the NextAuth.js repository or vice versa. You just need to install the next-auth package in your existing Next.js project and configure it.

  1. Install the next-auth package in your project directory.
  2. Create a [...nextauth].js file in the pages/api/auth directory of your project.
  3. Inside this file, import the NextAuth function from next-auth and call it with your configuration.

Here’s a basic example of a [...nextauth].js file in JavaScript:

const NextAuth = require('next-auth')
const Providers = require('next-auth/providers')

module.exports = NextAuth({
  providers: [
    Providers.Google({
      clientId: process.env.GOOGLE_ID,
      clientSecret: process.env.GOOGLE_SECRET
    }),
    // ...add more providers here
  ],
  database: process.env.DATABASE_URL,
})

Replace GOOGLE_ID, GOOGLE_SECRET, and DATABASE_URL with your actual values.

For more detailed information, you can refer to the NextAuth.js documentation and the Netlify documentation on Next.js.