In my Next.js project, I want to add authentication with next-auth@5 -beta. When I sign in using the google account, it gives 500 internal server error.(http://localhost:3000/api/auth/error?error=Configuration).
src/auth.js
import NextAuth from "next-auth";
import GoogleProvider from "next-auth/providers/google"
export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
],
secret: process.env.AUTH_SECRET
})
src/app/api/auth/[…nextauth]/route.js
import { handlers } from "@/auth"
export const { GET, POST } = handlers
src/app/page.js
import { redirect } from "next/navigation";
import { auth } from "@/auth";
export default async function Home() {
const session = await auth();
console.log(session)
if (!session) redirect("/api/auth/signin")
return (
<div>
HOMEPAGE
</div>
);
}
src/app/layout.js
import { Inter } from "next/font/google";
import "./globals.css";
const inter = Inter({ subsets: ["latin"] });
export const metadata = {
title: "Create Next App",
description: "Generated by create next app",
};
export default function RootLayout({ children }) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
</html>
);
}
New contributor
Nouman Younas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.