Error [ReferenceError]: Cannot access 'authConfig' before initialization #18540
Replies: 4 comments 1 reply
-
Also getting the same error, am on next-auth version 5.0.0-beta.19. I have two files, one for the config and the other for the actual auth: import Credentials from "next-auth/providers/credentials";
import type { NextAuthConfig } from "next-auth";
import { loginSchema } from "@/schemas/auth-schema";
import { getUserByEmail } from "@/queries/auth-queries";
import { scryptSync } from "crypto";
export const authConfig = {
providers: [
Credentials({
async authorize({ credentials }) {
const validatedData = loginSchema.safeParse(credentials);
if (!validatedData.success) return null;
const { email, password } = validatedData.data;
const user = await getUserByEmail(email);
if (!user || !user.password) return null;
const salt = user.password.slice(64);
const originalPassHash = user.password.slice(0, 64);
const currentPassHash = scryptSync(password, salt, 32).toString("hex");
const passIsValid = originalPassHash === currentPassHash;
if (!passIsValid) return null;
return user;
},
}),
],
} satisfies NextAuthConfig;
import NextAuth from "next-auth";
import { authConfig } from "./auth.config";
import { PrismaAdapter } from "@auth/prisma-adapter";
import { db } from "@/lib/db";
export const { auth, handlers, signIn, signOut } = NextAuth({
adapter: PrismaAdapter(db),
session: { strategy: "jwt" },
...authConfig,
}); My api route: import { handlers } from "@/auth";
export const { GET, POST } = handlers; |
Beta Was this translation helpful? Give feedback.
-
Please open an issue in the |
Beta Was this translation helpful? Give feedback.
-
This issue is still active, I encountered the same issue using next js 15.0.3 and next-auth 5.0.0-beta.25 |
Beta Was this translation helpful? Give feedback.
-
Please open this issue in |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
I've been working on setting up authentication in my Next.js application using NextAuth, and I've encountered a persistent issue that I hope to get some expert advice on.
Issue
I'm receiving the following error when trying to initialize my NextAuth configuration:
Here's the relevant code snippet and additional context:
auth.config.ts
auth.ts
I'm seeking guidance on the following:
Potential Causes: What could be causing this ReferenceError?
Best Practices: Are there any best practices for organizing and initializing NextAuth configurations to avoid such issues?
Troubleshooting Tips: Any additional debugging steps I should consider?
Beta Was this translation helpful? Give feedback.
All reactions