supabase / supabase-flutter

Flutter integration for Supabase. This package makes it simple for developers to build secure and scalable products.
https://supabase.com/
MIT License
656 stars 154 forks source link

AuthRetryableFetchError with Supabase and Flutter #909

Closed awalias closed 1 month ago

awalias commented 1 month ago

Discussed in https://github.com/orgs/supabase/discussions/23326

Originally posted by **BaHithBENON** April 27, 2024 Hello everyone ! I'm trying to implement authentication in my application, but when I start the process I have two problems: 1. `AuthRetryableFetchError` is returned and I don't know what it means, its statusCode is null 2. Sometimes I get the following error: `AuthException(message: Email rate limit exceeded, statusCode: 429)`. However, my limit is 30 per hour, and no emails have been initiated. 3. My Code bellow : ``` Future registerWithEmailAndPassword({ required String username, required String email, required String password, required String firstname, required String lastname, required String phone, required String phoneCode, }) async { // TODO: implement registerWithEmailAndPassword try { final response = await supabaseClient.auth.signUp( email: email, password: password, data: { 'username': username, 'email': email, 'firstname': firstname, 'lastname': lastname, 'phone_number': phone, 'phone_number_code': phoneCode, 'updated_at': DateTime.timestamp().toIso8601String(), 'created_at': DateTime.timestamp().toIso8601String(), 'is_active': false, 'is_deleted': false, 'token': null, } ); if(response.user == null) { throw const ServerException("User not found"); } return ModelUser.fromJson(response.user!.toJson()); } on AuthException catch (e) { print(e.message); throw ServerException(e.message); } catch (e) { throw ServerException(e.toString()); } } ``` 5. My database is active. Can anybody help me? I'm starting to get pretty frustrated
BaHithBENON commented 1 month ago

I finally found some solution...

I went into the server level logs, and saw that my user creation was failing due to type conversion. So, I modified my create function which is called when sending data in order to make the conversions more explicit.

    (new.raw_user_meta_data->>'is_active')::boolean,
    (new.raw_user_meta_data->>'is_deleted')::boolean

Postgres kept my boolean in text form (I don't know why).

And in my code, I send 0 or 1 instead of true or false.

      data: {
          'username': username,
          'email': email,
          'firstname': firstname,
          'lastname': lastname,
          'phone_number': phone,
          'phone_number_code': phoneCode,
          'updated_at': DateTime.timestamp().toIso8601String(),
          'created_at': DateTime.timestamp().toIso8601String(),
          'token': null,
          'is_active': 0,
          'is_deleted': 0,
      }
dshukertjr commented 1 month ago

Hi @BaHithBENON.

It looks like you have managed to solve your case, so I'm going to close this issue.

BaHithBENON commented 1 month ago

@awalias @dshukertjr Thanks !!!