User signup event in Auth0 Lock

只愿长相守 提交于 2019-12-22 06:47:23

问题


The 'authenticated' event is emitted after a successful authentication.

lock.on('authenticated', function(authResult) { });

But is there any way to detect when a new user signs up to your application or do I have to store the user in my database and check it each time a user authenticates?


回答1:


The Auth0 Lock does not trigger a specific event for user signup.

You can however detect this on a custom rule and enrich the user profile with this metadata. There's a signup sample rule that illustrates this possibility

function (user, context, callback) {
    user.app_metadata = user.app_metadata || {};

    // short-circuit if the user signed up already
    if (user.app_metadata.signed_up) return callback(null, user, context);

    // execute first time login/signup logic here
    // ...

    // update application metadata so that signup logic is skipped on subsequent logins
    user.app_metadata.signed_up = true;
    auth0.users.updateAppMetadata(user.user_id, user.app_metadata)
        .then(function () {
            callback(null, user, context);
        })
        .catch(function (err) {
            callback(err);
        });
}

This uses app_metadata to store information associated to the user so that you can keep track for which users you already executed their additional first-time signup logic.

Have in mind that rules will execute on the server-side of the authentication pipeline, so if the logic you want to implement requires user interaction you could achieve something similar by doing these set of steps:

  1. Upon login to the application get the user profile
  2. If there's no flag set assume the user just signed up and do your custom logic
  3. After doing your custom logic update the user app_metadata to set a signup flag (you can do this on your server-side application logic through Auth0 Management API)


来源:https://stackoverflow.com/questions/40250292/user-signup-event-in-auth0-lock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!