Auth.js Middleware
Hi!
This PR adds middleware for a Auth.js Server, it's still a WIP.
There's an issue with Jest and the @auth/core imports that's making it impossible to test currently. @yusukebe if you have suggestions please let me know.
⚠️ No Changeset found
Latest commit: 0b30e088e3cf2ba1a645d424cf6e5cb2f1e950c3
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
OK, I'll check it later!
Hi @ivoilic
This problem seems to be the Auth.js matter because the minimum project following will fail.
- https://github.com/yusukebe/jest-authjs
This is not an Auth.js problem, but a config issue, see the solution explained here: https://github.com/nextauthjs/next-auth/issues/6822#issuecomment-1447347641
Here is the actual sub-module being published correctly: https://unpkg.com/browse/@auth/[email protected]/providers/github.js, https://unpkg.com/browse/@auth/[email protected]/package.json
Hope this helps! :pray:
(PS: We would welcome this to be co-maintained from our official repo as @auth/hono if interested. :+1:)
Hi @balazsorban44 !
Thanks for your comment.
This is not an Auth.js problem, but a config issue
I'm sorry I doubted Auth.js!
@ivoilic
Could you check it?
@yusukebe I tried to follow @balazsorban44's (Thanks so much for taking the time to help with this!) example and made changes at the package level. This resolved the current issue but now I'm getting the error: ReferenceError: exports is not defined. I also tried making these changes at the root of the repo and was getting the same error with other imported packages. I'm not familiar enough with resolving these sort of packaging problems to make meaningful progress on this currently.
PS @balazsorban44 Love the idea of this being co-maintained, didn't know if it made more sense to add there or here. It would be great to have more client agnostic options for using auth.js!
ReferenceError: exports is not defined means you have CJS code that is being interpreted as ESM, since the CommonJS globals exports or module are not available in ES modules.
If you are fine with dropping CJS (some will argue but I recommend this), you can check out https://github.com/nextauthjs/next-auth/blob/main/packages/core/package.json
Basically you only need type: "modules" and the exports field in the package.json. The rest is legacy or non-spec properties.
Hi @ivoilic !
I've updated the jest version in the main branch. Can you merge it? After that, to avoid the error, it would be good not to use jest-environment-miniflare. So, set jest.config.js as follows according to @balazsorban44's advice.
module.exports = {
testMatch: ['**/test/**/*.+(ts|tsx|js)'],
transform: {
'^.+\\.(ts|tsx)$': ['ts-jest', { useESM: true }],
},
extensionsToTreatAsEsm: ['.ts'],
}
Then we cannot use crypto, so set it to global in the test code.
import crypto from 'crypto'
// ...
globalThis.crypto = crypto
And this may work.
We can't test without a GitHub token, so I would like to know if there is another good way to test that doesn't use third-party tokens.
does any one have a problem with
node:internal/modules/esm/resolve:303
return new ERR_PACKAGE_PATH_NOT_EXPORTED(
^
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /Users/bruger/Documents/Github/Semester_project_trustworthy/hub_server/node_modules/@auth/core/package.json
Hello everyone, can I take over this branch and start a new PR or is @ivoilic still available to have a look ?