1
我只是想創建一個離子移動應用程序(使用firebase)與電話號碼認證,但我不知道我應該如何繼續。有人可以幫助我嗎?謝謝。身份驗證whith電話號碼與firebase在ionic3
我只是想創建一個離子移動應用程序(使用firebase)與電話號碼認證,但我不知道我應該如何繼續。有人可以幫助我嗎?謝謝。身份驗證whith電話號碼與firebase在ionic3
你需要做以下步驟:
Activate Phone Number Authentication in your Firebase Console.
Set up reCAPTCHA verifier.
Send the SMS
Sign the user in.
的.html
<ion-content padding>
<div id="recaptcha-container"></div>
<ion-item>
<ion-label stacked>Phone Number</ion-label>
<ion-input type="number" [(ngModel)]="phoneNumber"></ion-input>
</ion-item>
<button ion-button id="sign-in-button" (click)="signIn(phoneNumber)">
Sign In
</button>
</ion-content>
.TS
signIn(phoneNumber: number){
const appVerifier = this.recaptchaVerifier;
const phoneNumberString = "+" + phoneNumber;
firebase.auth().signInWithPhoneNumber(phoneNumberString, appVerifier)
.then(confirmationResult => {
// SMS sent. Prompt user to type the code from the message, then sign the
// user in with confirmationResult.confirm(code).
let prompt = this.alertCtrl.create({
title: 'Enter the Confirmation code',
inputs: [{ name: 'confirmationCode', placeholder: 'Confirmation Code' }],
buttons: [
{ text: 'Cancel',
handler: data => { console.log('Cancel clicked'); }
},
{ text: 'Send',
handler: data => {
confirmationResult.confirm(data.confirmationCode)
.then(function (result) {
// User signed in successfully.
console.log(result.user);
// ...
}).catch(function (error) {
// User couldn't sign in (bad verification code?)
// ...
});
}
}
]
});
prompt.present();
})
.catch(function (error) {
console.error("SMS not sent", error);
});
}
這裏是Great article about it。我從上面的代碼中提取這是rticle。
謝謝ypu @Sampath。我會試試 – user8528238
確定沒問題:) – Sampath
它給了我這個錯誤(錯誤:./node_modules/firebase/utils/promise.js)Iwiil嘗試修復它,但如果你有任何想法... – user8528238