簡體   English   中英

未找到Meteor驗證方法

[英]Meteor validated method not found

我正在將我的Meteor應用程序從Meteor 1.2遷移到Meteor 1.3,並按照http://guide.meteor.com/methods.html#validated-method上的指南創建一個經過驗證的方法。

當我調用該方法時,我認為客戶端模擬正在發生,因為我可以注銷到控制台,但總是會出現錯誤Method '...' not found

/imports/ui/pages/register.js

import {Meteor} from 'meteor/meteor';
import {Template} from 'meteor/templating';
import {FlowRouter} from 'meteor/kadira:flow-router';

// Methods
import {createAccount} from '/imports/api/accounts/methods.js';

// HTML
import './register.html';

Template.Register_page.events({
  'submit form': function(event) {
    event.preventDefault();

    var user = {
      email: $('#email').val(),
      password: $('#password').val(),
      profile: {
        firstName: $('#firstName').val(),
        lastName: $('#lastName').val()
      }
    };

    createAccount.call(user, function(err) {
      if (err) {
        console.error(err);
      } else {
        console.log('User successfully registered');
        FlowRouter.go('Dashboard');
      }
    });
  }
});

/imports/api/accounts/methods.js

import {Meteor} from 'meteor/meteor';
import {ValidatedMethod} from 'meteor/mdg:validated-method';
import {SimpleSchema} from 'meteor/aldeed:simple-schema';
import {Accounts} from 'meteor/accounts-base';

export const createAccount = new ValidatedMethod({
  name: 'createAccount',
  validate: new SimpleSchema({
    email: { type: String },
    password: { type: String },
    profile: { type: Object },
    "profile.firstName": { type: String },
    "profile.lastName": { type: String }
  }).validator(),
  run(user) {
    console.log(user);
    Accounts.createUser(user);
  },
});

客戶控制台

Object {email: "test@mailinator.com", password: "testPassw0rd", profile: Object}    methods.js:18
errorClass {error: 404, reason: "Method 'createAccount' not found", details: undefined, message: "Method 'createAccount' not found [404]", errorType: "Meteor.Error"}    register.js:28

我認為這不起作用的原因是因為我沒有在啟動時初始化服務器上​​的javascript。

添加以下內容解決了以下問題:

/imports/startup/server/index.js

import './register-api.js';

/imports/startup/server/register-api.js

import '/imports/api/accounts/methods.js';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM