adrien2p / medusa-plugins

A collection of awesome plugins for medusa :rocket:
https://medusa-plugins.vercel.app
MIT License
144 stars 42 forks source link

An error occurred while registering endpoints in medusa-plugin-auth TypeError: app.use() requires a middleware function #129

Closed luluhoc closed 6 months ago

luluhoc commented 6 months ago

I'm getting this error i'm using medusa 1.19

warn:    An error occurred while registering endpoints in medusa-plugin-auth
warn:    TypeError: app.use() requires a middleware function
    at Function.use (/Users/lucjangrzesik/Desktop/retrobroker/server/node_modules/express/lib/application.js:217:11)
    at /Users/lucjangrzesik/Desktop/retrobroker/server/node_modules/@medusajs/medusa/dist/loaders/plugins.js:436:37
    at step (/Users/lucjangrzesik/Desktop/retrobroker/server/node_modules/@medusajs/medusa/dist/loaders/plugins.js:56:23)
    at Object.next (/Users/lucjangrzesik/Desktop/retrobroker/server/node_modules/@medusajs/medusa/dist/loaders/plugins.js:37:53)
⠹ Initializing plugins

my config

{
    resolve: "medusa-plugin-auth",
    /** @type {import('medusa-plugin-auth').AuthOptions} */
    options: {
      // strict: "all", // or "none" or "store" or "admin"
      google: {
        clientID: GoogleClientId,
        clientSecret: GoogleClientSecret,

        admin: {
          callbackUrl: `${BACKEND_URL}/admin/auth/google/cb`,
          failureRedirect: `${ADMIN_URL}/login`,

          // The success redirect can be overriden from the client by adding a query param `?redirectTo=your_url` to the auth url
          // This query param will have the priority over this configuration
          successRedirect: `${ADMIN_URL}/`,

          authPath: '/admin/auth/google',
          // authCallbackPath: '/admin/auth/google/cb',
          // expiresIn: 24 * 60 * 60 * 1000,
          // verifyCallback: (container, req, accessToken, refreshToken, profile, strict) => {
          //    // implement your custom verify callback here if you need it
          // }
        },

        store: {
          callbackUrl: `${BACKEND_URL}/store/auth/google/cb`,
          failureRedirect: `${STORE_URL}/login`,

          // The success redirect can be overriden from the client by adding a query param `?redirectTo=your_url` to the auth url
          // This query param will have the priority over this configuration
          successRedirect: `${STORE_URL}/`,

          authPath: '/store/auth/google',
          authCallbackPath: '/store/auth/google/cb',
          // expiresIn: 24 * 60 * 60 * 1000,
          // verifyCallback: (container, req, accessToken, refreshToken, profile, strict) => {
          //     console.log('verifyCallback')
          //     console.log(profile)
          //     console.log(accessToken)
          //     console.log(refreshToken)

          //    // implement your custom verify callback here if you need it
          // }
        }
      }
    }
  },
luluhoc commented 6 months ago

@adrien2p

adrien2p commented 6 months ago

I suggest you to look at this one https://discord.com/channels/876835651130097704/1192132522285469715 i ve already provided a solution 😊

luluhoc commented 6 months ago

I suggest you to look at this one https://discord.com/channels/876835651130097704/1192132522285469715 i ve already provided a solution 😊

oh, thanks it's working now

aldo-roman commented 5 months ago

@adrien2p I cannot see the link. It somehow doesn't load. Could you please share the solution here?

adrien2p commented 5 months ago

It is here https://discord.com/channels/876835651130097704/1192132522285469715 this doesn't open?

you can use the 1.9.1 the options looks like this

{
    resolve: "medusa-plugin-auth",
    /** @type {import('medusa-plugin-auth')} */
    options: [{
      type: "google",
      identifier: "google",
      clientID:
        "...",
      clientSecret: "...",
      admin: {
        callbackUrl: "http://localhost:9000/admin/auth/google/cb",

        failureRedirect: "http://localhost:7001/login",
        successRedirect: "http://localhost:7001/",

        authPath: "/admin/auth/google",
        authCallbackPath: "/admin/auth/google/cb",
      },
      store: {
        callbackUrl: "http://localhost:9000/store/auth/google/cb",

        failureRedirect: "http://localhost:8000/account/login",
        successRedirect: "http://localhost:8000/",

        authPath: "/store/auth/google",
        authCallbackPath: "/store/auth/google/cb",
      },
    },
    {
      type: "facebook",
      identifier: "facebook",
      clientID: "...",
      clientSecret: "...",
      admin: {
        callbackUrl: "http://localhost:9000/admin/auth/facebook/cb",

        failureRedirect: "http://localhost:7001/login",
        successRedirect: "http://localhost:7001/",

        authPath: "/admin/auth/facebook",
        authCallbackPath: "/admin/auth/facebook/cb",
      },
    }],
  },
aldo-roman commented 5 months ago

Somehow the discord link won't open for me. Thanks for sharing here. I guess it's better here, too.