Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auth.js Middleware #52

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Auth.js Middleware #52

wants to merge 5 commits into from

Conversation

ivoilic
Copy link

@ivoilic ivoilic commented Feb 19, 2023

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.

@changeset-bot
Copy link

changeset-bot bot commented Feb 19, 2023

⚠️ No Changeset found

Latest commit: 0b30e08

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

@yusukebe
Copy link
Member

OK, I'll check it later!

@yusukebe
Copy link
Member

Hi @ivoilic

This problem seems to be the Auth.js matter because the minimum project following will fail.

SS

@balazsorban44
Copy link

balazsorban44 commented Feb 28, 2023

This is not an Auth.js problem, but a config issue, see the solution explained here: nextauthjs/next-auth#6822 (comment)

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! 🙏

(PS: We would welcome this to be co-maintained from our official repo as @auth/hono if interested. 👍)

@yusukebe
Copy link
Member

yusukebe commented Mar 6, 2023

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?

@ivoilic
Copy link
Author

ivoilic commented Mar 11, 2023

@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!

@balazsorban44
Copy link

balazsorban44 commented Mar 12, 2023

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.

@yusukebe
Copy link
Member

yusukebe commented Mar 21, 2023

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.

@Fnux8890
Copy link

Fnux8890 commented Mar 7, 2024

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

@neolectron
Copy link

Hello everyone, can I take over this branch and start a new PR or is @ivoilic still available to have a look ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants