You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sign up with an already registered email returns type cast error #100
When the response.rawData is null and response.error is not, signUpWithEmail catches a type cast error instead of the actual error from the fetch operation.
In a previous version this was not an issue, because the type casting was done after the response.error evaluation.
To reproduce
Use an email that is already registered.
final client =SupabaseClient('URL', 'KEY');
// Sign up user with email and passwordfinal response =await client.auth.signUp('[email protected]', 'adsjbda1');
print('response.data: ${response.data}');
print('response.rawData: ${response.rawData}');
print('response.error: ${response.error}');
response.data: null
response.rawData: null
response.error: GotrueError(message: type 'Null' is not a subtype of type 'Map<String, dynamic>' in type cast)
Expected
response.data: null
response.rawData: null
response.error: GotrueError(message: User already registered)
Because the actual response from the fetch operation is:
{
"code": 400,
"msg": "User already registered"
}
How I changed the code locally
Modified the signUpWithEmail in gotrue_api.dart.
From:
final data = response.rawData asMap<String, dynamic>;
if (response.error !=null) {
returnGotrueSessionResponse(error: response.error);
} elseif (data['access_token'] ==null) {
...
To:
Map<String, dynamic>? data = response.rawData;
if (response.error !=null) {
returnGotrueSessionResponse(error: response.error);
} elseif (data !=null&& data['access_token'] ==null) {
...
This isn't actually an issue with the library. If you change
final data = response.rawData asMap<String, dynamic>;
to
final data = response.rawData asMap<String, dynamic>?;
, it should start working. This happens because of Dart's null-safety. If you cast it as Map<String, dynamic> (non-nullable), but the value is null, a type error will be thrown.
This is code from the library, as I mentioned in the "How I changed the code locally" section. Yes, the ? should do it (when casting, as well when using it), but it has to be done in the library.
Activity
bdlukaa commentedon Apr 25, 2022
This isn't actually an issue with the library. If you change
to
, it should start working. This happens because of Dart's null-safety. If you cast it as
Map<String, dynamic>(non-nullable), but the value is null, a type error will be thrown.sorineugen commentedon Apr 25, 2022
This is code from the library, as I mentioned in the "How I changed the code locally" section. Yes, the ? should do it (when casting, as well when using it), but it has to be done in the library.
bdlukaa commentedon Apr 25, 2022
Ooh! I thought it was yours, sorry! Indeed, this is an issue! Thanks for reporting <3
sorineugen commentedon Apr 25, 2022
bdlukaa commentedon Apr 25, 2022
sorineugen commentedon Apr 25, 2022
bdlukaa commentedon Jul 20, 2022
Similar to supabase/gotrue-dart#79
feat: add region as forceFunctionRegion query parameter
feat: add region as forceFunctionRegion query parameter (#1243)