Based on the information provided in the extracts, it seems like you're trying to set up authentication using NextAuth.js with GitHub as a provider. The issue you're facing might be related to the setup of your API routes or the configuration of your NextAuth.js setup.
In Next.js, any file inside the pages/api directory is treated as an API endpoint and is server-side only. These API routes are publicly accessible and can handle requests from outside the application. They are not limited to internal requests only.
For your GitHub authentication, you need to set up a specific route for authentication as required by NextAuth.js. This is done by creating a new file in the pages/api/auth directory named [...nextauth].ts. This file should contain the configuration for your NextAuth.js setup with your GitHub OAuth credentials and the Prisma adapter.
Here's the boilerplate code for the [...nextauth].ts file:
import { NextApiHandler } from 'next';
import NextAuth from 'next-auth';
import { PrismaAdapter } from '@next-auth/prisma-adapter';
import GitHubProvider from 'next-auth/providers/github';
import prisma from '../../../lib/prisma';
const authHandler: NextApiHandler = (req, res) => NextAuth(req, res, options);
export default authHandler;
const options = {
providers: [
GitHubProvider({
clientId: process.env.GITHUB_ID,
clientSecret: process.env.GITHUB_SECRET,
}),
],
adapter: PrismaAdapter(prisma),
secret: process.env.SECRET,
};
(Source: Vercel Guide (https://vercel.com/guides/nextjs-prisma-postgres))
If you're still facing issues, it might be due to the configuration of your GitHub OAuth credentials or the setup of your Prisma adapter. Make sure these are correctly configured. Also, ensure that your callback URL is correctly set up in your GitHub OAuth app settings.