Description
Describe the bug
I've encountered an issue with the signInWithPassword
method in the Supabase Flutter SDK (version 2.4.1) where authentication fails despite using valid credentials that work with direct API calls.
Issue Description:
- Authentication using
supabase.auth.signInWithPassword()
fails with "Invalid login credentials" error (400 status code) - The same exact credentials authenticate successfully via direct HTTP POST to the REST endpoint
Environment:
- Supabase Flutter SDK: 2.4.1
- Flutter: 3.24.3
- Platform: Android (tested on emulator)
To Reproduce
Steps to reproduce the behavior:
- Initialize Supabase Flutter SDK with valid URL and anon key
- Call
supabase.auth.signInWithPassword()
with valid credentials - Observe the "Invalid login credentials" error
- Make a direct HTTP POST to
/auth/v1/token?grant_type=password
with the same credentials - Observe successful authentication with 200 status code
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Version (please complete the following information):
On Linux/macOS
Please run dart pub deps | grep -E "supabase|gotrue|postgrest|storage_client|realtime_client|functions_client"
in your project directory and paste the output here.
├── supabase_flutter 2.8.4
│ ├── supabase 2.6.3
│ │ ├── functions_client 2.4.1
│ │ ├── gotrue 2.11.1
│ │ ├── postgrest 2.4.1
│ │ ├── realtime_client 2.4.2
│ │ ├── storage_client 2.3.1
Additional context
May be relevant - I'm not a programmer. Working closely with Claude 3.7 sonnet (via Claude Code) to build Flutter app running on iOS and Android. Recently switched from Firebase to Supabase - and ran into this issue.
Working Direct API Code:
final url = 'https://mibgwobvweznhxowqvip.supabase.co/auth/v1/token?grant_type=password';
final headers = {
'apikey': '<anon_key>',
'Content-Type': 'application/json',
};
final body = jsonEncode({
'email': email,
'password': password,
});
final response = await http.post(Uri.parse(url), headers: headers, body: body);
// Status code 200 - Success
Failing SDK Code:
final response = await supabase.auth.signInWithPassword(
email: email,
password: password,
);
// AuthException(message: Invalid login credentials, statusCode: 400, errorCode:
invalid_credentials)
I've implemented a workaround by directly calling the REST API, but this circumvents the benefits of using the SDK.