使用角度

时间:2016-09-18 16:46:33

标签: typescript auth0 angularjs-1.5

我正在尝试在同一个调用中添加更多userinfo。首先使用用户名,Auth0中的密码然后在回调上注册继续将userinfo添加到我的数据库。但我无法让这个工作。即使用户已经存在于Auth0-db中,它也会访问API。

以下是AuthService中的代码:

public signup(signupForm, callback) {
const self = AuthService._instance;
var result = "";


self._angularAuth0.signup({
  connection: "Users",
  responseType: "token",
  email: signupForm.email,
  password: signupForm.password
}, (error) => {
    console.log(error);        
}, this.onSignupSuccess(signupForm));    
}

private onSignupSuccess(form) {
const self = AuthService._instance;

const newUser = {
  firstName: form.firstName,
  lastName: form.lastName,
  email: form.email,
  birthdate: new Date(form.birthYear, form.birthMonth, form.birthDay),
  auth0_UserId: this.userProfile.user_id,
  gender: form.gender
};

self._dataService.add(this.baseUrl + "/users/", newUser);
}

内部app.ts:

angularAuth0Provider.init({
    clientID: "3LGkdfVvFfdsdfMpz1UVcwjh1jktrf7j",
    domain: "somedomain.eu.auth0.com",
    callbackURL: "http://127.0.0.1:8080/authorized",
});

1 个答案:

答案 0 :(得分:0)

你应该在回调中加入this.onSignupSuccess。目前,它作为第三个参数传递给signup方法,这就是它始终被执行的原因。

self._angularAuth0.signup({
    connection: "Users",
    responseType: "token",
    email: signupForm.email,
    password: signupForm.password,
    auto_login: false
}, (error) => {
    console.log(error);
    if(!error){
        this.onSignupSuccess(signupForm);
    }
});

此后您可以手动登录用户。请参阅示例here