admin管理员组文章数量:1125600
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:
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.
本文标签: javascriptFailed to compile Unknown module type in Nextjs with NextAuthjsStack Overflow
版权声明:本文标题:javascript - Failed to compile: Unknown module type in Next.js with NextAuth.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736669400a1946833.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论