Receiving this error whenever i run npm run dev.
Full error:
⨯ TypeError: (0 , _next_auth_firebase_adapter__WEBPACK_IMPORTED_MODULE_2__.default) is not a function
at admin (c:\Users\user\Downloads\Muscat\src\pages\api\auth\[...nextauth].js:47:27)
45 | }),
46 | ],
> 47 | adapter: FirebaseAdapter(admin.firestore()),
| ^
48 | callbacks: {
49 | async session({ session, user }) {
50 | session.user.id = user.id;
Tried to uninstall using commands and reinstall but issue still persists.
Command used for uninstallation: npm uninstall @next-auth/firebase-adapter
Command used for reinstallation: npm install @next-auth/firebase-adapter
FULL CODE:
import NextAuth from "next-auth";
import GoogleProvider from "next-auth/providers/google";
import FirebaseAdapter from "@next-auth/firebase-adapter";
import { cert } from "firebase-admin/app";
import admin from "firebase-admin";
// Get the raw env variable
const rawServiceAccount = process.env.FIREBASE_ADMIN_CREDENTIALS;
// Debug: Check if the variable is set
console.log("RAW ADMIN CREDS:", rawServiceAccount);
if (!rawServiceAccount) {
throw new Error("FIREBASE_ADMIN_CREDENTIALS is missing! Check your .env.local.");
}
// Parse JSON safely
let serviceAccount;
try {
serviceAccount = JSON.parse(rawServiceAccount);
} catch (error) {
throw new Error("FIREBASE_ADMIN_CREDENTIALS is not valid JSON. Check .env.local formatting.");
}
// Debug: Ensure private key is correctly formatted
if (!serviceAccount.private_key) {
throw new Error("Parsed FIREBASE_ADMIN_CREDENTIALS does not contain a private_key.");
}
// Ensure private_key newlines are properly formatted
serviceAccount.private_key = serviceAccount.private_key.replace(/\\n/g, "\n");
// Initialize Firebase Admin
if (!admin.apps.length) {
admin.initializeApp({
credential: cert(serviceAccount),
});
}
export default NextAuth({
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
],
adapter: FirebaseAdapter(admin.firestore()),
callbacks: {
async session({ session, user }) {
session.user.id = user.id;
return session;
},
},
});