我的应用正在使用Meteor + Angular2(此应用基于Urigo's tutorial)(最后是package.json)
我正在尝试在用户注册后重定向用户。 但我有这个错误:
提供调用'登录'注册/ http:// localhost:3000 / app / app.js的结果有异常?hash = 5d5262809ea4c507a654caa1a722dfd2ec17a3b9:164:21 userCallback @ http://localhost:3000/packages/accounts-password.js?hash=6d4e41828e1dfcc45ff74267779a4e5ecdcd9eda:105:23
我的用户已在我的应用程序中成功注册并登录,但未重定向到他的个人资料...我尝试使用有和没有ngZone ...我可能会误解某些内容。
这是我的signup.component.ts注册码:
signup() {
if (this.signupForm.valid) {
let user = {
email: this.signupForm.value.email,
password: this.signupForm.value.password,
profile: {
player: {
playersName: this.signupForm.value.playersName,
region: this.signupForm.value.region
}
}
}
Meteor.call('createUserWithRole', user, function(err, userId) {
Meteor.loginWithPassword(user.email, user.password, function(err, success){
this.zone.run(() => {
if (err) {
this.error = err;
} else {
this.router.navigate(['/my-profile']);
}
});
});
});
}
}
这是我的服务器/ user / user.methods.ts
Meteor.methods({
'createUserWithRole': function(data) {
//console.log(data);
check(data, {
email: String,
password: String,
profile: {
player: {
playersName: String,
region: String
}
}
});
let userId;
userId = Accounts.createUser({
email: data.email,
password: data.password,
profile: {
newHistory: false,
player: {
playerId: null,
avatar: null,
playerName: data.profile.player.playersName,
playercname: data.profile.player.playersName.replace(/\s+/g, '').toLowerCase(),
region: data.profile.player.region,
revisionDate: null,
lastManualUpdate: null
}
}
});
Roles.addUsersToRoles(userId, [
'active',
'1man_q',
'2men_q',
'3men_q',
'4men_q',
'5men_q',
'global_chat',
'captain',
'report',
'chat_global',
'chat_lobby',
'comment',
'vote',
'support',
'default'
], 'user_default');
return data;
},...others methods...skipped...
和我的package.json
{
"name": "angular2-meteor-base",
"private": true,
"scripts": {
"start": "meteor --settings settings-development.json",
"start:prod": "meteor run --production",
"build": "meteor build ./build/",
"clear": "meteor reset",
"meteor:update": "meteor update --all-packages",
"test": "meteor test --driver-package practicalmeteor:mocha",
"test:ci": "meteor test --once --driver-package dispatch:mocha-phantomjs"
},
"devDependencies": {
"@types/chai": "3.4.34",
"@types/meteor": "^1.3.31",
"@types/mocha": "2.2.34",
"chai": "3.5.0",
"chai-spies": "0.7.1",
"meteor-node-stubs": "0.2.4"
},
"dependencies": {
"@angular/common": "2.4.1",
"@angular/compiler": "2.4.1",
"@angular/core": "2.4.1",
"@angular/forms": "2.4.1",
"@angular/platform-browser": "2.4.1",
"@angular/platform-browser-dynamic": "2.4.1",
"@angular/router": "3.4.1",
"angular2-meteor": "0.7.1",
"angular2-meteor-accounts-ui": "^1.0.0",
"angular2-meteor-polyfills": "0.1.1",
"angular2-meteor-tests-polyfills": "0.0.2",
"babel-runtime": "^6.18.0",
"bootstrap": "^4.0.0-alpha.3",
"meteor-rxjs": "0.4.7",
"ng2-bootstrap": "^1.3.1",
"reflect-metadata": "0.1.9",
"rxjs": "5.0.2",
"zone.js": "0.7.4"
}
}
答案 0 :(得分:1)
您需要将您的功能绑定到当前环境。
Meteor.call('createUserWithRole', user, function(err, userId) {
Meteor.loginWithPassword(user.email, user.password, function(err, success) {
this.zone.run(function(){
if (err) {
this.error = err;
} else {
this.router.navigate(['/my-profile']);
}
}.bind(this));
}.bind(this));
}.bind(this));
答案 1 :(得分:0)
我认为这可能是由于JavaScript关闭造成的。 this.router
在这种情况下不存在,但我不确定你为什么会得到你当时得到的错误。
试试这个:
Meteor.call('createUserWithRole', user, (err, userId) => {
Meteor.loginWithPassword(user.email, user.password, (err, success) => {
this.zone.run(() => {
if (err) {
this.error = err;
} else {
this.router.navigate(['/my-profile']);
}
});
});
});