Is it possible to have Phone auth as sign-in method in Firebase, but use Twilio for the OTP message?
I created a Cloud Function that successfully sends the OTP message to my user:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const twilio = require('twilio');
const accountSid = 'xxx';
const authToken = 'xxx';
const client = new twilio(accountSid, authToken);
exports.sendOTP = functions.region('europe-central2').https.onCall((data, context) => {
const phoneNumber = data.phoneNumber;
const otp = Math.floor(100000 + Math.random() * 900000).toString(); // Generate a 6-digit OTP
return client.messages.create({
body: `Your verification code is ${otp}`,
from: 'xxx',
to: phoneNumber
}).then((message) => {
return { success: true, otp: otp };
}).catch((error) => {
return { success: false, error: error.message };
});
});
But... how do I create the user now in the Firebase Authentication? I can create a document inside the users collection - that's not the problem, but how do I create it inside Firebase Auth? Do I create another Cloud Function for this?