Reputation: 24
I'm working on a project using Next.js v15.0.1 and NextAuth.js v5.0.0-beta.25. When I run my app, I encounter the following error:
Unknown module type
This module doesn't have an associated type. Use a known file extension, or register a loader for it.
Read more: https://nextjs.org/docs/app/api-reference/next-config-js/turbo#webpack-loaders
The issue occurs when I try to get the session data in the middleware.js file using the auth function provided by NextAuth.js in the auth.js file I use only the credentials provider in NextAuth. Here's my code:
// middleware.js
import { NextResponse } from 'next/server';
import { auth } from './auth';
export function middleware(request) {
const { data } = auth();
const token = request.cookies.get('authjs.session-token');
console.log('token', token);
console.log(data);
return NextResponse.next();
}
export const config = {
matcher: ['/login', '/signup'],
};
// auth.js
import NextAuth from 'next-auth';
import Credentials from 'next-auth/providers/credentials';
import { authorizeUser } from '@/lib/auth/user';
export const { auth, handlers, signIn, signOut } = NextAuth({
providers: [
Credentials({
credentials: {
email: {},
password: {},
},
authorize: authorizeUser,
}),
],
secret: process.env.NEXTAUTH_SECRET,
});
// next.config.mjs
/** @type {import('next').NextConfig} */
const nextConfig = {};
export default nextConfig;
I tried using the auth() function from auth.js to get the session data inside middleware.js and log it to the console.I expected the session data to be returned and for the application to compile without errors.
Upvotes: 0
Views: 582
Reputation: 1
In your authorizeUser function, are you using bcrypt? I also got the same error and solved it by removing bcrypt. How do I salt & hash the password then? Currently I have no solution for this.
I really should look into the error stack trace and maybe opening a new issue either on Next.js or Auth.js github
Upvotes: 0