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

Support for using a custom SessionProcessor and SessionResource in UserManagementAddon #345

Open
joelalejandro opened this issue Mar 13, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@joelalejandro
Copy link
Member

joelalejandro commented Mar 13, 2023

Right now, the login callback is very lean and simple, receiving two arguments:

type LoginCallbackSignature = (op: Operation, user: ResourceAttributes) => boolean;

It is possible that more data is required to do a login operation, and that such data lives in other resources. Ideally we'd want to access Knex from here, but we need to resort to function factories to do so:

app.use(UserManagementAddon, {
   // ...
   userLoginCallback: myLogin(app.services.knex)
});

const myLogin = (knex: Knex) => (op: Operation, user: ResourceAttributes) => {
  // knex...
}

Since we already allow the UserProcessor to be customized, we should allow SessionProcessor and SessionResource as well. Processors extending from KnexProcessor have access to the service via this.knex.

Usage of the addon would then look like:

app.use(UserManagementAddon, {
  userResource: MyUser,
  userProcessor: MyUserProcessor,
  sessionResource: MySession,
  sessionProcessor: MySessionProcessor,
});

Such a processor would be defined as:

      class MySessionProcessor<T extends Session> extends JsonApiSessionProcessor<T> {
        public static resourceClass = MySession; // extends Session

        protected async login(op: Operation, userDataSource: ResourceAttributes): Promise<boolean> {
          // Do the login.
        }
      }
@joelalejandro joelalejandro added the enhancement New feature or request label Mar 13, 2023
@joelalejandro joelalejandro self-assigned this Mar 13, 2023
@joelalejandro joelalejandro changed the title Support for using a custom SessionProcessor in UserManagementAddon Support for using a custom SessionProcessor and SessionUser in UserManagementAddon Mar 13, 2023
@joelalejandro joelalejandro changed the title Support for using a custom SessionProcessor and SessionUser in UserManagementAddon Support for using a custom SessionProcessor and SessionResource in UserManagementAddon Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant