diff --git a/flutter/lib/features/auth/data/auth_providers.dart b/flutter/lib/features/auth/data/auth_providers.dart index 78d6c500..e31aa73b 100644 --- a/flutter/lib/features/auth/data/auth_providers.dart +++ b/flutter/lib/features/auth/data/auth_providers.dart @@ -20,10 +20,10 @@ class AuthNotifier extends AsyncNotifier { return ref.watch(authRepositoryProvider).getToken(); } - Future login(String email, String password) async { + Future 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), ); } diff --git a/flutter/lib/features/auth/data/auth_repository.dart b/flutter/lib/features/auth/data/auth_repository.dart index 1154f5b4..7860e46e 100644 --- a/flutter/lib/features/auth/data/auth_repository.dart +++ b/flutter/lib/features/auth/data/auth_repository.dart @@ -8,16 +8,16 @@ class AuthRepository { AuthRepository(this._api, this._storage); - Future login(String email, String password) async { + Future 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; - final token = data['access_token'] as String; + final token = data['accessToken'] as String; await _storage.saveToken(token); return token; } diff --git a/flutter/lib/features/auth/presentation/login_screen.dart b/flutter/lib/features/auth/presentation/login_screen.dart index e0278f9e..3ef19094 100644 --- a/flutter/lib/features/auth/presentation/login_screen.dart +++ b/flutter/lib/features/auth/presentation/login_screen.dart @@ -11,19 +11,19 @@ class LoginScreen extends ConsumerStatefulWidget { } class _LoginScreenState extends ConsumerState { - final _emailCtrl = TextEditingController(); + final _usernameCtrl = TextEditingController(); final _passwordCtrl = TextEditingController(); @override void dispose() { - _emailCtrl.dispose(); + _usernameCtrl.dispose(); _passwordCtrl.dispose(); super.dispose(); } Future _submit() async { await ref.read(authStateProvider.notifier).login( - _emailCtrl.text.trim(), + _usernameCtrl.text.trim(), _passwordCtrl.text, ); if (mounted) { @@ -45,9 +45,8 @@ class _LoginScreenState extends ConsumerState { mainAxisAlignment: MainAxisAlignment.center, children: [ TextField( - controller: _emailCtrl, - decoration: const InputDecoration(labelText: 'E-post'), - keyboardType: TextInputType.emailAddress, + controller: _usernameCtrl, + decoration: const InputDecoration(labelText: 'Anvandarnamn'), ), const SizedBox(height: 12), TextField(