0

我正在尝试在同一呼叫中添加更多用户信息。首先在 Auth0 中使用用户名、密码进行注册,然后在回调中继续将用户信息添加到我的数据库中。但我无法让它工作。即使用户已经存在于 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",
});
4

1 回答 1

0

你应该把this.onSignupSuccesscall 放在回调里面。目前它作为第三个参数传递给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);
    }
});

之后,您可以手动登录用户。请参阅此处的示例。

于 2016-09-19T05:32:09.773 回答