Meteor 在客户端和服务器之间共享会话数据

Meteor share sessions data between client and server

我正在构建受限注册。我希望具有在 url 中传递的特定代码的用户能够注册,而不是其他人。我正在使用 accounts 包。

我可以在 Accounts.onCreateUser 方法中阻止创建帐户。我正在寻找一种方法来告诉服务器客户端是否有授权的注册代码。使用经典形式(电子邮件+密码),我可以添加一个额外的隐藏字段。如果用户使用 Facebook 注册,我如何才能获得相同的结果?

由于 Meteor 不使用 cookie,我无法将此信息存储在服务器可以访问的 cookie 中。 Session 服务器端无法访问变量。由于我无法控制通过 account-facebook 创建发送的内容,因此我无法在客户端使用 Session 变量,当用户按下注册时我会传递该变量。

有什么想法吗?

只需将特殊令牌添加到传递给 Accounts.createUser() 的用户对象:

var user = {
    email: email,
    password: password,
    profile: {
        token: token
    }
};
Accounts.createUser(user, function (error, result) {
    if (error) {
        console.log(error)
    }
});

在服务器端,您可以在 Accounts.onCreateUser():

中访问它
Accounts.onCreateUser(function(options, user) {
    console.log(options);
    console.log(user);
});

认为 您可以在选项变量中找到您的令牌,因此它将是 options.profile.token.

对我来说,最好的选择是将自定义参数传递给登录按钮。

查看包文档: https://github.com/ianmartorell/meteor-accounts-ui-bootstrap-3

其中概述了以下内容:

    accountsUIBootstrap3.setCustomSignupOptions = function() {
        return {
            mxpDistinctId: Session.get('mxpdid'),
            leadSource: Session.get('leadSource')
        }
    };