diff --git a/docs/source/api/accounts-multi.md b/docs/source/api/accounts-multi.md index 644a28970f..8689b15859 100644 --- a/docs/source/api/accounts-multi.md +++ b/docs/source/api/accounts-multi.md @@ -315,6 +315,15 @@ Accounts.setAdditionalFindUserOnExternalLogin(({serviceName, serviceData}) => { } }) ``` +{% apibox "AccountsServer#registerLoginHandler" %} + +Use this to register your own custom authentication method. This is also used by all of the other inbuilt accounts packages to integrate with the accounts system. + +There can be multiple login handlers that are registered. When a login request is made, it will go through all these handlers to find its own handler. + +The registered handler callback is called with a single argument, the `options` object which comes from the login method. For example, if you want to login with a plaintext password, `options` could be `{ user: { username: }, password: }`,or `{ user: { email: }, password: }`. + +The login handler should return `undefined` if it's not going to handle the login request or else the login result object.

Rate Limiting

diff --git a/packages/accounts-base/accounts_server.js b/packages/accounts-base/accounts_server.js index 76da1fe072..f677baa34c 100644 --- a/packages/accounts-base/accounts_server.js +++ b/packages/accounts-base/accounts_server.js @@ -547,19 +547,14 @@ export class AccountsServer extends AccountsCommon { /// LOGIN HANDLERS /// - // The main entry point for auth packages to hook in to login. - // - // A login handler is a login method which can return `undefined` to - // indicate that the login request is not handled by this handler. - // - // @param name {String} Optional. The service name, used by default - // if a specific service name isn't returned in the result. - // - // @param handler {Function} A function that receives an options object - // (as passed as an argument to the `login` method) and returns one of: - // - `undefined`, meaning don't handle; - // - a login method result object - + /** + * @summary Registers a new login handler. + * @locus Server + * @param {String} [name] The type of login method like oauth, password, etc. + * @param {Function} handler A function that receives an options object + * (as passed as an argument to the `login` method) and returns one of + * `undefined`, meaning don't handle or a login method result object. + */ registerLoginHandler(name, handler) { if (! handler) { handler = name;