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

Plugin doesn't run in Payload 2.0 and errors out in connect-mongo #15

Open
koriolis opened this issue Nov 14, 2023 · 2 comments
Open

Plugin doesn't run in Payload 2.0 and errors out in connect-mongo #15

koriolis opened this issue Nov 14, 2023 · 2 comments

Comments

@koriolis
Copy link

Hi, I'm a bit of newbie on PayloadCMS and Authentication in general.
I've installed and configured the plugin as instructed on the README but unfortunately I'm running into this error which is kind of baffling me.
This is the beginning of my configuration of the plugin to start testing if it works, hence the userinfo callback is very simple just logging the token it gets and returning a dummy user (I don't know what the sub property is supposed to contain, and I'm assuming it's supposed to be either the payload user id or the oauth user.id).

Anyway this fails before even executing so I'm stuck at the moment, and in the off chance this is a known solved problem, I'm opening this issue. Will be glad to provide any additional information. Thanks!

Relevant packages versions

  • Payload 2.0.14
  • Plugin Oauth: 2.0.1
  • Bundler Vite: 0.1.3
  • db-mongodb: 1.0.5

Setup

// ...
import { oAuthPlugin } from 'payload-plugin-oauth';
// ...
export default buildConfig({
  // ...
  plugins: [
    oAuthPlugin({
      databaseUri: process.env.MONGODB_URI,
      clientID: process.env.CLIENT_ID,
      clientSecret: process.env.CLIENT_SECRET,
      authorizationURL: process.env.AUTHORIZATION_URL,
      tokenURL: process.env.TOKEN_URL,
      callbackURL: `${process.env.SERVER_URL}/api/oauth/callback`,
      async userinfo(acessToken) {
       console.dir(accessToken);
       return {
          sub: 'my-user-id-on-payload',
          name: 'John Smith',
          email: 'user@domain.com'
       };
      }
    })
  ],
  db: mongooseAdapter({
    url: process.env.MONGODB_URI
  })
});

Error

✘ [ERROR] Could not read from file: /home/my-cms/false

    node_modules/payload-plugin-oauth/dist/index.js:8:48:
      8 │ const connect_mongo_1 = __importDefault(require("connect-mongo"));
@MikaelSiidorow
Copy link

The plugin does not seem to support Vite as a bundler currently, theres some direct references to Webpack:

webpack: (webpackConfig) => {
const config = incoming.admin?.webpack?.(webpackConfig) || webpackConfig
return {
...config,
resolve: {
...config.resolve,
alias: {
...config.resolve?.alias,
'connect-mongo': false,
'express-session': false,
'passport-oauth2': false,
jsonwebtoken: false,
passport: false,
},
},
}

@koriolis
Copy link
Author

The plugin does not seem to support Vite as a bundler currently, theres some direct references to Webpack:

webpack: (webpackConfig) => {
const config = incoming.admin?.webpack?.(webpackConfig) || webpackConfig
return {
...config,
resolve: {
...config.resolve,
alias: {
...config.resolve?.alias,
'connect-mongo': false,
'express-session': false,
'passport-oauth2': false,
jsonwebtoken: false,
passport: false,
},
},
}

Thanks @MikaelSiidorow. I'll see if it's possible to translate these aliases into Vite and maybe add them in the global vite configuration (no sure if it's possible though).

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

No branches or pull requests

2 participants