2016-09-18 33 views
0

我想在同一個調用中添加更多的用戶信息。首先使用用戶名,密碼在Auth0,然後在回調中註冊,繼續添加userinfo到我的數據庫。但我無法得到這個工作。即使用戶已經存在於Auth0-db中,它也會擊中API。使用auth0角度的自定義註冊過程

這裏是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 + "https://stackoverflow.com/users/", newUser); 
} 

內app.ts:

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

回答

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

+0

它不起作用。在它碰到onSignupSuccess方法之前,它重定向到callbackUrl。 – n3tx

+0

也許是問題的callbackURL? – n3tx

+0

默認情況下,auth0會在成功註冊後自動登錄用戶。嘗試指定'auto_login:false'選項 –