Closed barryengineerapart closed 1 year ago
Currently having this issue where nothing from the auth
files marked as server-only
, which contain sensitive data, can be imported into middlewares, specially the ongoing v5 that directly requires importing the auth
config file into the middleware file.
This is unrelated to NextAuth.js. already tracked on the Next.js side. https://github.com/vercel/next.js/issues/54549
@adrianyg7 FWIW I've tested this locally a few times, and have deployment where this works. Make sure you are on the latest Next.js/NextAuth.js version. 🤔
@adrianyg7 FWIW I've tested this locally a few times, and have deployment where this works. Make sure you are on the latest Next.js/NextAuth.js version. 🤔
Does that mean that this issue has been solved>
Environment
Reproduction URL
https://codesandbox.io/p/sandbox/vigorous-ace-sx277k?file=/middleware.ts:1,1
Describe the issue
Nextjs13 will fail to build when using
server-only
with middleware (even if the middleware is empty like so):This is problematic for AuthJS which uses middleware which is exposed to sensitive information that must not be in any circumstances be shared with the client. This could be a problem with NextJS (see https://github.com/vercel/next.js/issues/55206) which may be incorrectly including some middleware components in the client build.
How to reproduce
Expected behavior
Since the current guidance of AuthJS is to use middleware that potentially exposes client secrets, the thinking is that the middleware should never be exposed to a client build. This could be a Next problem, however next may also be using middleware on the client (I can't be sure).
However, the expected behavior is that AuthJS can be used in a safe/secure manner, and so there should be some way to ensure the middleware can use server functions without exposing sensitive info to the client. Perhaps this could mean using
fetch
(which may increase the latency somewhat).