最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - User signup event in Auth0 Lock - Stack Overflow

programmeradmin3浏览0评论

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?

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?

Share Improve this question edited Oct 26, 2016 at 8:47 João Angelo 57.8k13 gold badges147 silver badges148 bronze badges asked Oct 25, 2016 at 21:47 JoeJoe 4,27432 gold badges106 silver badges180 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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)
发布评论

评论列表(0)

  1. 暂无评论