【问题标题】:Meteor Collections schema not allowing Google authenticationMeteor Collections 架构不允许 Google 身份验证
【发布时间】:2015-06-06 11:38:29
【问题描述】:

我正在使用 MeteorJS 构建一个简单的用户帐户。用户只能选择使用 Google 登录/注册。如果他们是第一次注册,用户在使用他们的用户帐户进行身份验证后会被提示填写他们的个人资料信息。

我正在使用 Collections2 来管理用户帐户的架构并将其附加到 Meteor.users,如下所示:

var Schemas = {};


Schemas.UserProfile = new SimpleSchema({
    firstName: {
        type: String,
        regEx: /^[a-zA-Z-]{2,25}$/,
        optional: true
    },
    lastName: {
        type: String,
        regEx: /^[a-zA-Z]{2,25}$/,
        optional: true
    },
    gender: {
        type: String,
        allowedValues: ['Male', 'Female'],
        optional: true
    }
});


Schemas.User = new SimpleSchema({
    username: {
        type: String,
        regEx: /^[a-z0-9A-Z_]{3,15}$/
    },

    _id : {
        type: String
    },

    createdAt: {
        type: Date
    },
    profile: {
        type: Object
    },
    services: {
        type: Object,
        blackbox: true
    },
    // Add `roles` to your schema if you use the meteor-roles package.
    // Option 1: Object type
    // If you specify that type as Object, you must also specify the
    // `Roles.GLOBAL_GROUP` group whenever you add a user to a role.
    // Example:
    // Roles.addUsersToRoles(userId, ["admin"], Roles.GLOBAL_GROUP);
    // You can't mix and match adding with and without a group since
    // you will fail validation in some cases.
    //roles: {
    //    type: Object,
    //    optional: true,
    //    blackbox: true
    //}
    // Option 2: [String] type
    // If you are sure you will never need to use role groups, then
    // you can specify [String] as the type
    roles: {
        type: [String],
        optional: true
    }
});


Meteor.users.attachSchema(Schemas.users);

注册账号的时候报错:

调用方法“登录”时出现异常错误:当修饰符 选项为真,验证对象必须至少有一个运算符

我是 Meteor 的新手,我不确定这个错误是什么意思。我似乎找不到关于这个问题的任何文档。我尝试修改我的 Meteor.users.allow 和 Meteor.users.deny 权限以查看是否有任何效果,但这似乎是我使用 collections2 包的方式的一些潜在问题。

更新 - 已解决: 我的代码最底部的一个错字导致了错误:

我有Meteor.users.attachSchema(Schemas.users); 应该是Meteor.users.attachSchema(Schemas.User);

也类似于 @Ethaan 发布的内容,我应该将我的 Schemas.User.profile 类型引用到 profile: { type: Schemas.UserProfile }

这样,我的用户配置文件设置将根据 UserProfile 架构进行验证,而不仅仅是作为对象进行验证。

【问题讨论】:

    标签: meteor meteor-collection2


    【解决方案1】:

    似乎其中一个选项为 null 或 dosnt 存在。

    createdAt,profile,username,services.
    

    就像错误所说的那样,它正在验证但不存在,例如,您正在尝试验证配置文件对象,但没有配置文件对象,因此它没有进入架构。

    当修饰符选项为真时

    这部分是因为默认情况下,所有键都是必需的。设置optional: true。所以看看登录/注册工作流程的问题在哪里。将选项更改为false

    例如,更改配置文件字段上的可选项。

    Schemas.User = new SimpleSchema({
        username: {
            type: String,
            regEx: /^[a-z0-9A-Z_]{3,15}$/
        },
    
        _id : {
            type: String
        },
    
        createdAt: {
            type: Date
        },
        profile: {
            type: Object,
            optional:false, // for example
        },
        services: {
            type: Object,
            blackbox: true
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2014-02-19
      • 2015-12-25
      • 2012-12-09
      • 1970-01-01
      • 2014-06-07
      • 1970-01-01
      • 2018-04-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多