Ошибка простой схемы в Метеоре
Я использую учетные записи метеоров и простую схему для пользователей, чтобы зарегистрироваться и ввести информацию о своем профиле в моем приложении. Я определил схему для пользователей и прикрепил схему к адресу. Однако, когда я иду, чтобы зарегистрировать учетную запись, я получаю сообщение об ошибке "Требуется адрес", хотя я заполнил все необходимые поля для адреса. Вот моя схема:
Schemas.UserAddress = new SimpleSchema({ //UserAddress schema defined
streetAddress: {
type: String,
max: 100,
optional: false
},
city: {
type: String,
max: 50,
optional: false
},
state: {
type: String,
regEx: /^A[LKSZRAEP]|C[AOT]|D[EC]|F[LM]|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEHINOPST]|N[CDEHJMVY]|O[HKR]|P[ARW]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY]$/,
optional: false
},
zipCode: {
type: String,
regEx: /^[0-9]{5}$/,
optional: false
}});
var Schemas = {};
Schemas.UserProfile = new SimpleSchema({
companyName: {
type: String,
regEx: /^[a-zA-Z-]{2,25}$/,
optional: false
},
tireMarkup: {
type: Number,
optional: true,
min: 1
},
phoneNum: {
type: String,
regEx: /^[(]{0,1}[0-9]{3}[)]{0,1}[-\s\.]{0,1}[0-9]{3}[-\s\.]{0,1}[0-9]{4}$/,
optional: false
},
confirmed: {
type: Boolean,
optional: true
},
});
Schemas.User = new SimpleSchema({
emails: {
type: [Object],
optional: false
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
"emails.$.verified": {
type: Boolean
},
createdAt: {
type: Date
},
profile: {
type: Schemas.UserProfile,
optional: false
},
address: { //Attach user address schema
type: Schemas.UserAddress,
optional: false
},
services: {
type: Object,
optional: true,
blackbox: true
}
});
Meteor.users.attachSchema(Schemas.User);
Вот мой конфиг учетных записей, который создает форму регистрации:
Meteor.startup(function () {
AccountsEntry.config({
logo: '', // if set displays logo above sign-in options
termsUrl: '/terms-of-use', // if set adds link to terms 'you agree to ...' on sign-up page
homeRoute: '/', // mandatory - path to redirect to after sign-out
dashboardRoute: '/dashboard/', // mandatory - path to redirect to after successful sign-in
profileRoute: '/profile',
passwordSignupFields: 'EMAIL_ONLY',
showOtherLoginServices: true, // Set to false to hide oauth login buttons on the signin/signup pages. Useful if you are using something like accounts-meld or want to oauth for api access
extraSignUpFields: [
{
field: "companyName",
label: "Company Name",
placeholder: "Petrocon",
type: "text",
required: true
},
{
field: "firstName",
label: "First Name",
placeholder: "John",
type: "text",
required: true
},
{
field: "lastName",
label: "Last Name",
placeholder: "Nguyen",
type: "text",
required: true
},
{ field: "streetAddress",
label: "Street Address",
placeholder: "12345 Main Street",
type: "text",
required: true
},
{ field: "city",
label: "City",
placeholder: "Springfield",
type: "text",
required: true
},
{ field: "state",
label: "State",
placeholder: "Missouri",
type: "text",
required: true
},
{ field: "zipCode",
label: "Zip Code",
placeholder: "65801",
type: "text",
required: true
},
{
field: "phoneNum",
label: "Contact Number",
placeholder: "316-000-0000",
type: "text",
required: true
}
]
});
});
Как вы можете видеть, я определил все поля в схеме адресов в AccountsEntry.config.. поэтому я не знаю, почему, когда я ввожу всю информацию в форму, я получаю сообщение об ошибке "Требуется адрес". Кто-нибудь знает, что происходит? Заранее спасибо!
1 ответ
Похоже, вы используете пакет для входа в аккаунт. Вы можете увидеть код создания учетной записи в этом файле:
Строка 29 выглядит так:
profile: _.extend(profile, user.profile)
Если вы выполните отладку и посмотрите на значение профиля после вызова метода extends, вы увидите следующее:
{
"companyName": "Petrocon",
"firstName": "John",
"lastName": "Nguyen",
"streetAddress": "12345 Main Street",
"city": "Springfield",
"state": "Missouri",
"zipCode": "65801",
"phoneNum": "316-000-0000"
}
Для вашей схемы Schemas.User нет свойства с именем "address".
Может быть какой-то хитрый способ сделать то, что вы ищете, но самый простой подход - просто избавиться от схемы Schemas.UserAddress. Переместите эти свойства (streetAddress, city, state, zipCode) в схему Schemas.UserProfile, и она будет работать.