fix: update login functionality to use username instead of email

This commit is contained in:
Nils-Johan Gynther
2026-04-21 22:17:09 +02:00
parent b87c877b38
commit eceb94c604
3 changed files with 10 additions and 11 deletions
@@ -20,10 +20,10 @@ class AuthNotifier extends AsyncNotifier<String?> {
return ref.watch(authRepositoryProvider).getToken();
}
Future<void> login(String email, String password) async {
Future<void> login(String username, String password) async {
state = const AsyncLoading();
state = await AsyncValue.guard(
() => ref.read(authRepositoryProvider).login(email, password),
() => ref.read(authRepositoryProvider).login(username, password),
);
}
@@ -8,16 +8,16 @@ class AuthRepository {
AuthRepository(this._api, this._storage);
Future<String> login(String email, String password) async {
Future<String> login(String username, String password) async {
final response = await _api.post(
'/auth/login',
jsonEncode({'email': email, 'password': password}),
jsonEncode({'username': username, 'password': password}),
);
if (response.statusCode != 200 && response.statusCode != 201) {
throw Exception('Login failed: ${response.statusCode}');
}
final data = jsonDecode(response.body) as Map<String, dynamic>;
final token = data['access_token'] as String;
final token = data['accessToken'] as String;
await _storage.saveToken(token);
return token;
}