流星集合模式不允许Google身份验证 [英] Meteor Collections schema not allowing Google authentication

查看:97
本文介绍了流星集合模式不允许Google身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MeteorJS建立一个简单的用户帐户.仅向用户提供使用Google登录/注册的选项.如果是初次注册,则使用用户帐户进行身份验证后,系统会提示用户填写其个人资料信息.

I'm building a simple user account using MeteorJS. A user is only given the option to login/register using Google. If they are registering for the first time, users will be prompted to fill out their profile information after authenticating with their user account.

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

I'm using Collections2 to manage the schema for a user account and attaching it to Meteor.users, which is seen here:

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

注册帐户时出现错误:

调用方法登录"时发生异常错误:当修饰符 选项为true,验证对象必须至少具有一个运算符

Exception while invoking method 'login' Error: When the modifier option is true, validation object must have at least one operator

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

I'm new to Meteor and I'm not sure what this error means. I can't seem to find any documentation on the issue. I've tried modifying my Meteor.users.allow and Meteor.users.deny permissions to see if that has any effect, but it seems to be some underlying issue with the way I'm using the collections2 package.

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

UPDATE - RESOLVED: This one typo at the very bottom of my code was causing the error:

我在哪里Meteor.users.attachSchema(Schemas.users); 应该是Meteor.users.attachSchema(Schemas.User);

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

Also similar to what @Ethaan posted, I should have referred my Schemas.User.profile type to profile: { type: Schemas.UserProfile }

这样,将根据UserProfile模式对用户的个人资料设置进行验证,而不仅仅是将其作为对象进行验证.

That way, my user's profile settings will be validated based off of the UserProfile schema, rather than just being validated as an object.

推荐答案

该选项之一似乎为空或不存在.

It seems like one of this options are null or dosnt exists.

createdAt,profile,username,services.

像错误一样,它表明已被验证但已存在dosnt,例如您正在尝试验证配置文件对象,但是没有配置文件对象,因此它在架构上没有任何作用.

Like the error says something its getting validated but dosnt exists, for example you are trying to validate the profile object, but there is not profile object so nothing its getting on the schema.

当修饰符选项为true

When the modifier option is true

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

This part is because By default, all keys are required. Set optional: true. so to see where is the problem on the login/registrato workflow. change the option to false.

例如,在配置文件字段中更改可选项.

For example, change the optional on the profile field.

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

这篇关于流星集合模式不允许Google身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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