How can I access firestore data before authenticating phone number?

Issue

In my flutter app I want to create a phone authentication for sign up, with one condition that only those phone numbers, which are already been stored in firestore database can sign up.. ….. How can I access firestore data before signing in?

Solution

Register a blocking function for beforeCreate event and check that a user’s phoneNumber is in a list of allowed numbers. If not throw an error.

Triggers before a new user is saved to the Firebase Authentication database, and before a token is returned to your client app.

const functions = require('firebase-functions');

exports.beforeCreate = functions.auth.user().beforeCreate((user, context) => {
  // TODO check user.phoneNumber againts allowed ones
});

See Extend Firebase Authentication with blocking Cloud Functions for details.

Answered By – user18309290

Answer Checked By – Pedro (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *