Below is the error I am geting
[next-auth][error][CLIENT_FETCH_ERROR]
https://next-auth.js.org/errors#client_fetch_error Unexpected token '<', "<!DOCTYPE "... is not valid JSON
{error: {…}, url: '/api/auth/session', message: `Unexpected token '<', "<!DOCTYPE "... is not valid JSON`
I have reviewed my configuration and it seems correct, wondering why I'm encountering this issue.
Here's my setup :
- Google Client ID and Secret: I've set up the Google client ID and secret in my environment variables.
- NextAuth Configuration: I'm using the GoogleProvider from NextAuth with the correct clientId and clientSecret.
- SessionProvider: I have a SessionProvider wrapping my components to provide session data.
Despite double-checking everything, this error persists.
Below is NextAuth Configuration:
api/auth/[...nextauth].js
import NextAuth from "next-auth";
import GoogleProvider from "next-auth/providers/google";
const handler = NextAuth({
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
],
});
export { handler as GET, handler as POST };
AuthProvider.js:
import { SessionProvider } from "next-auth/react";
const AuthProvider = ({ children }) => {
return <SessionProvider>{children}</SessionProvider>;
};
export default AuthProvider;
**// RootLayout.js**
import { Inter } from "next/font/google";
import { ThemeProvider } from "../context/ThemeContext";
import AuthProvider from "../app/components/AuthProvider/AuthProvider";
const inter = Inter({ subsets: ["latin"] });
export const metadata: Metadata = {
title: "Testing",
description: "This is the description",
};
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body className={inter.className}>
<ThemeProvider>
<AuthProvider>
<div className="container">
{children}
</div>
</AuthProvider>
</ThemeProvider>
</body>
</html>
);
}
I attempted to implement authentication in my Next.js app using NextAuth with the Google provider. I I configured the Google Client ID and Secret, set up the NextAuth configuration using the GoogleProvider, and wrapped my components in a SessionProvider for session management.