Flutter OTP for password changing

89 Views Asked by At

When I request for OTP on my flutter application then it is sent to me and its stored in the firestore, but once I try to use the otp and change password it wont work. I get this error:

OTP email sent to [email protected]
isOtpValid called with email: [email protected], otp: 309624
storedOtp: 309624, otpExpiresAt: 1682282143752
current time: 1682281565543
XMLHttpRequest error.

Everything seems to work and the service account seems to be correct, but then again it's not fully working.

I did try to see the logs which seem to say that permission is denied, but the service account is okay.

static Future<String> createCustomToken(String uid) async {
    final url =
        'https://europe-west1-goatmentor-firebase.cloudfunctions.net/createCustomToken';
    final response = await http.post(
      Uri.parse(url),
      body: {'uid': uid},
    );

    if (response.statusCode == 200) {
      var jsonResponse = jsonDecode(response.body);
      if (jsonResponse['success']) {
        return jsonResponse['customToken'];
      } else {
        throw Exception(
            'Error creating custom token: ${jsonResponse['message']}');
      }
    } else {
      throw Exception(
          'Failed to create custom token. Status code: ${response.statusCode}');
    }
  }
0

There are 0 best solutions below