Auth0 Lock中的用户注册事件 [英] User signup event in Auth0 Lock

查看:147
本文介绍了Auth0 Lock中的用户注册事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

成功验证后会发出'已验证的'事件。

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?

推荐答案

Auth0 Lock不会触发特定事件用户注册。

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);
        });
}

这使用 app_metadata 存储与用户关联的信息,以便您可以跟踪已执行其他首次注册逻辑的用户。

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. 登录应用程序后获取用户个人资料

  2. 如果没有标记集假定用户刚刚注册并执行自定义逻辑

  3. 执行自定义逻辑更新后,用户 app_metadata 设置注册flag(您可以通过 Auth0 Management API 在服务器端应用程序逻辑上执行此操作)

  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)

这篇关于Auth0 Lock中的用户注册事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆