#Using cacheService in Auth Provider leads to AwilixResolutionError

6 messages · Page 1 of 1 (latest)

manic basin
#

Hey! I'm not sure if I'm misinterpreting the documentation or whether I've stumbled onto a bug.

I'm trying to use the CacheService in an Auth Provider to store state and PKCE values across OAuth redirects. I'm aware it's probably not the right thing to do! I ran into an AilixResolutionError that meant the Provider I created was crashing when trying to resolve the cacheService, which several parts of the docs at least alude to being accessible:

https://docs.medusajs.com/resources/architectural-modules/cache/create#4-use-module - mentioning the cacheService key specifically

https://docs.medusajs.com/resources/medusa-container-resources#module-container-resources - mentioning Modules' services using camelcase'd names

To that end, I added a key, cacheService into the first argument of my Provider's constructor, like so:

  constructor(
    { logger, cacheService }: { logger: Logger, cacheService: ICacheService },
    options: Options
  ) {
    super(...arguments);

    this.cacheService_ = cacheService;
    ...
  }

The types are all happy with what I've done, but when accessing the http://[storefront_url]/auth/user/oauth-generic endpoint I was getting an error which didn't make sense:

Unable to retrieve the auth provider with id: oauth-generic
Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.

I double and triple verified that my Provider oauth-generic was available, but the error persisted. After some more investigation, I found a catch block that was swallowing the real error. After patching @medusajs/auth/dist/services/auth-provider.js:31 to throw the error in the CLI, I got the real error:

AwilixResolutionError: Could not resolve 'cacheService'.

Resolution path: au_oauth-generic -> cacheService

[ 1/2 ]

#

I did also try loading in some Commerce Module services instead of an Architectural Module and even an unrelated custom module I created, but I had no luck with any of them.

My main question is, have I made a mistake, or should I open a bug ticket!

I will open a ticket in GH for the auth-provider.js error swallowing separately.

[ 2/2 ]

snow garden
#

You can't, by design, use any service/module outside the ones in your second link(logger, manager etc). The services at the end refer to internal services to the module.

You can't use any external modules, including the commercial ones. Instead you're supposed to use subscribers/workflows (to enforce module isolation).

I'm having the same issue with a fulfillment provider where i want to access the product module. I've moved it to a subscriber, which works for my use case but I still find it annoying and unnecessary.

snow garden
#

actually, in this issue https://github.com/medusajs/medusa/issues/10487 i found that you can add external module dependencies to your module. It works for me as i'm also making a fulfillment provider, but it might not for other providers. It's worth a shot tho.

I spent all day trying to solve this, they should really document this option better

GitHub

Package.json file { "name": "ship", "version": "0.0.1", "description": "SHIP for Eight Sleep", "author": "Eight Sleep"...

manic basin
#

Heck yes, thanks for that! It looks like it should fix my problem too!

manic basin
#

I tried that just now and it worked a treat!