n3tx n3tx - 2 months ago 24
TypeScript Question

custom signup procedure using auth0 in angular

I am trying to add more userinfo in same call. First signup with username, password in Auth0 and then on the callback continue to add userinfo to my database. But I can't get this to work. It hits the API even if the user is already existing in the Auth0-db.

Here is the code within the 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);
}


Inside app.ts:

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

Answer

You should put this.onSignupSuccess call inside callback. Currently it is passed as third parameter to signup method, that's why it is always executed.

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);
    }
});

After this you can login user manually. See examples here.

Comments