How to send and verify OTP using cloud function in flutter?

118
  1. Setup firebase cloud function here

  2. Your js code be like

    exports.sendOtp = functions.https.onCall((request, response) => {
          const options = JSON.stringify({
            mobile: request.text,
          });
          const headers = {
            "Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxx”,
          };
          const res = axios.post(“url”, options, {headers: headers}).then((response) => {
            console.log(response);
            return response;
          });
          return res.statusCode;
        });
    
    
  3. Your service code be like

    Future<void> sendOtp(String mobile) async {
        HttpsCallable callable =
            FirebaseFunctions.instance.httpsCallable('sendOtp');
        final resp = await callable.call(<String, dynamic>{
          'text': mobile,
        });
     }
Share:
118
Steve Vinoski
Author by

Steve Vinoski

Erlang, distributed systems, Yaws, Emacs, C++

Updated on January 04, 2023

Comments

  • Steve Vinoski
    Steve Vinoski over 1 year

    I have API to send and verify otp code. I need to link that API to my flutter app using Firebase clod function. How is it possible Please help ?