In my Web Administration Page made in Flutter that uses Supabase, I have a function/page to create a new user. However, I am encountering the error “AuthException(message: AuthRetryableFetchError, statusCode: null)” when trying to execute the insertion of the user. I have this function/data repository that inserts the data first in the auth.users table then to the public.profiles table for the user’s details.
Here is the data repository code:
Future<String?> createUserAndProfile(
String email,
String password,
String firstName,
String middleName,
String lastName,
String accountType,
String? empId,
int? regionId,
int? provinceId,
int? municipalityId) async {
final supabase = Supabase.instance.client;
try {
final authResponse =
await supabase.auth.signUp(email: email, password: password);
if (authResponse.user == null) {
return "Error in saving in database (auth)";
}
final user = authResponse.user!;
final profileResponse = await supabase.from('profiles').insert({
'id': user.id,
'email': email,
'firstname': firstName,
'middlename': middleName,
'lastname': lastName,
'account_type': accountType,
'employee_id': empId,
'region_id': regionId,
'province_id': provinceId,
'municipality_id': municipalityId,
});
if (profileResponse.error != null) {
return 'Error creating profile: ${profileResponse.error!.message}';
} else {
print('Profile created successfully!');
return null;
}
} on AuthException catch (e) {
return e.message; // Return the specific error message from AuthException
} catch (e) {
return 'An unexpected error occurred: ${e.toString()}';
}
}
Here is the code snippet/function to where the function above is called:
Future<void> _handleSignUp() async {
if (_formKey.currentState!.validate()) {
final email = _emailController.text.trim();
final password = _passwordController.text.trim();
final firstName = _firstNameController.text.trim();
final middleName = _middleNameController.text.trim();
final lastName = _lastNameController.text.trim();
final empId = _employeeIdController.text.trim();
/*
print('Email: $email, password: $password');
print('Name: $firstName $middleName $lastName');
print('Employee Number: $empId');
print(
'Region: $_selectedRegionId, Province: $_selectedProvinceId, Municipality: $_selectedMunicipalityId');
*/
final errorMessage = await createUserAndProfile(
email,
password,
firstName,
lastName,
middleName,
_accountType!,
empId,
_selectedRegionId,
_selectedProvinceId,
_selectedMunicipalityId);
// Handle successful signup or potential errors
// (e.g., show a success message or handle signup errors)
_errorMessage.value = errorMessage;
}
}
I have tried to check if the values being passed to function are correct (the commented part above) and they are correct. When I tried to submit, the error message was “AuthRetryableFetchError”. The user is not being inserted in the auth.users table and consequently in the profiles table. How can I debug what is wrong with my code, or did I miss some configuration for Supabase?
I tried using CoPilot and Gemini but both have generic answers that there may be a temporary network disruption or problem with the server. However, I am using a self-hosted Supabase using Docker and I had no trouble during the login process in my Web Application which uses the Supabase Auth.
Here is the schema of my profiles data:
CREATE TABLE profiles (
id UUID REFERENCES auth.users NOT NULL PRIMARY KEY,
updated_at TIMESTAMP with time zone,
lastname VARCHAR(30) NOT NULL,
firstname VARCHAR(30) NOT NULL,
middlename VARCHAR(30),
account_type VARCHAR(20) NOT NULL,
employee_id VARCHAR(30),
region_id INT REFERENCES regions(id),
province_id INT REFERENCES provinces(id),
municipality_id INT REFERENCES municipalities(id)
);