Skip to content

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

@joelalejandro

Description

@joelalejandro

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.
        }
      }

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions