Error: The edge runtime does not support Node.js 'crypto' module.
I dont know what i'm doing wrong during the setup of next auth
```
import type { NextAuthConfig } from "next-auth"
import Credentials from "next-auth/providers/credentials";
import { LoginSchema } from "@/schemas";
import { getUserByEmail } from "@/data/user";
import bcrypt from "bcryptjs";
export default {
providers: [
Credentials({
async authorize(credentials) {
if(!credentials) return null;
const validatedFields = LoginSchema.safeParse(credentials);
if(validatedFields.success) {
const {email, password} = validatedFields.data;
const user = await getUserByEmail(email);
if(!user || !user.password) return null;
const passwordsMatch = await bcrypt.compare(
password,
user.password,
);
if(passwordsMatch) return {
...user,
id: String(user.id),
};
}
return null;
}
})
],
} satisfies NextAuthConfig
import type { NextAuthConfig } from "next-auth"
import Credentials from "next-auth/providers/credentials";
import { LoginSchema } from "@/schemas";
import { getUserByEmail } from "@/data/user";
import bcrypt from "bcryptjs";
export default {
providers: [
Credentials({
async authorize(credentials) {
if(!credentials) return null;
const validatedFields = LoginSchema.safeParse(credentials);
if(validatedFields.success) {
const {email, password} = validatedFields.data;
const user = await getUserByEmail(email);
if(!user || !user.password) return null;
const passwordsMatch = await bcrypt.compare(
password,
user.password,
);
if(passwordsMatch) return {
...user,
id: String(user.id),
};
}
return null;
}
})
],
} satisfies NextAuthConfig
import NextAuth from "next-auth"
import { DrizzleAdapter } from "@auth/drizzle-adapter"
import { db } from "@/lib/db";
import authConfig from "@/auth.config"
export const { handlers, auth, signIn, signOut } = NextAuth({
adapter: DrizzleAdapter(db),
session: {strategy: "jwt"},
...authConfig,
})
import NextAuth from "next-auth"
import { DrizzleAdapter } from "@auth/drizzle-adapter"
import { db } from "@/lib/db";
import authConfig from "@/auth.config"
export const { handlers, auth, signIn, signOut } = NextAuth({
adapter: DrizzleAdapter(db),
session: {strategy: "jwt"},
...authConfig,
})
2 Replies
import NextAuth from "next-auth";
import authConfig from "@/auth.config";
import {
DEFAULT_LOGIN_REDIRECT,
apiAuthPrefix,
authRoutes,
publicRoutes
} from "@/routes";
const { auth } = NextAuth(authConfig);
export default auth((req) => {
const { nextUrl } = req;
const isLoggedIn = !!req.auth;
const isApiAuthRoute = nextUrl.pathname.startsWith(apiAuthPrefix);
const isPublicRoute = publicRoutes.includes(nextUrl.pathname);
const isAuthRoute = authRoutes.includes(nextUrl.pathname);
if (isApiAuthRoute) return null;
if(isAuthRoute) {
if (isLoggedIn) return Response.redirect(new URL(DEFAULT_LOGIN_REDIRECT, nextUrl));
else return null;
}
if(!isLoggedIn && !isPublicRoute) return Response.redirect(new URL("/auth/login", nextUrl));
else return null;
})
export const config = {
matcher: [
'/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
'/(api|trpc)(.*)',
],
};
import NextAuth from "next-auth";
import authConfig from "@/auth.config";
import {
DEFAULT_LOGIN_REDIRECT,
apiAuthPrefix,
authRoutes,
publicRoutes
} from "@/routes";
const { auth } = NextAuth(authConfig);
export default auth((req) => {
const { nextUrl } = req;
const isLoggedIn = !!req.auth;
const isApiAuthRoute = nextUrl.pathname.startsWith(apiAuthPrefix);
const isPublicRoute = publicRoutes.includes(nextUrl.pathname);
const isAuthRoute = authRoutes.includes(nextUrl.pathname);
if (isApiAuthRoute) return null;
if(isAuthRoute) {
if (isLoggedIn) return Response.redirect(new URL(DEFAULT_LOGIN_REDIRECT, nextUrl));
else return null;
}
if(!isLoggedIn && !isPublicRoute) return Response.redirect(new URL("/auth/login", nextUrl));
else return null;
})
export const config = {
matcher: [
'/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
'/(api|trpc)(.*)',
],
};
did you find the solution ??