Skip to content
This repository has been archived by the owner on Sep 27, 2021. It is now read-only.

Extending Providers example error #359

Open
HigoRibeiro opened this issue Mar 25, 2019 · 1 comment
Open

Extending Providers example error #359

HigoRibeiro opened this issue Mar 25, 2019 · 1 comment

Comments

@HigoRibeiro
Copy link

Today I was asked to help someone in need of authentication with Ad (Active Directory) and I indicated the AdonisJS documentation (Extending Providers) that shows how to do this and I came across what I considered an error:

  • In the example it shows that we should use hooks.after, but I understand that hooks.before should be used, because when the manager is called to get his extensions it is empty ([]). Once the extensions are called after the Providers are registered.
  • In the example it is shown how to extend the Adonis/Src/Session provider, but this provider does not exist and to extend an authentication provider is slightly different, as the example below.

Extend provider Auth with new scheme

ioc.extend(
    "Adonis/Src/Auth",
    "ad",
    function() {
      return class ADScheme {},
    "scheme"
  );

Thank you

@HigoRibeiro HigoRibeiro changed the title Extending Providers Extending Providers example error Mar 26, 2019
@backspacerhino
Copy link

I would like to extend on this problem with a more concrete example with core code

In the documentation (Extending providers) it sohuld be noted that 'Adonis/Src/Session' is actually going to call Manager from session

If we go to Manager.js in Session, or in my case Auth we get this:

extend (key, implementation, type) {

and if I call this in start/hooks.js file like so (Test is imported at the top and is being initialized here)

hooks.after.providersRegistered(() => {
ioc.extend('Adonis/Src/Auth', 'test', function () {
return new Test();
})
})

it doesn't work because of two reasons

  1. I need to put hooks.before or I get error saying that my test serializer needs to be defined
  2. There is a fourth parameter missing that will specify that we are creating a serializer

And so the proper code looks like this

hooks.before.providersRegistered(() => {
ioc.extend('Adonis/Src/Auth', 'test', function () {
return new Test();
},'serializer')
})

and now it works.

Another problem is in Ioc.extend documentation in code where it doesn't state that there need to be four paramaters, but only 3 (and this is also true for website docs)

@thetutlage thetutlage removed the triage label Nov 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants