diff --git a/Mobile/lib/api.dart b/Mobile/lib/api.dart index 7a4e6a8..4a4276c 100644 --- a/Mobile/lib/api.dart +++ b/Mobile/lib/api.dart @@ -2,16 +2,13 @@ import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; -import 'dart:developer'; enum ApiService { auth, app, } -Future request(BuildContext context, ApiService service, String method, - String path, Object? body) async { - log('hello'); +Future request(BuildContext context, ApiService service, String method, String path, Object? body) async { final messenger = ScaffoldMessenger.of(context); final host = switch (service) { @@ -19,9 +16,6 @@ Future request(BuildContext context, ApiService service, String method, ApiService.app => const String.fromEnvironment('APP_SERVICE_HOST'), }; - log('hello'); - log(const String.fromEnvironment('AUTH_SERVICE_HOST')); - final http.Response response; try { @@ -42,8 +36,7 @@ Future request(BuildContext context, ApiService service, String method, ); } } catch (_) { - messenger.showSnackBar( - const SnackBar(content: Text('Unable to connect to server'))); + messenger.showSnackBar(const SnackBar(content: Text('Unable to connect to server'))); return null; } @@ -52,8 +45,7 @@ Future request(BuildContext context, ApiService service, String method, final json = jsonDecode(response.body); messenger.showSnackBar(SnackBar(content: Text(json['message']))); } catch (_) { - messenger.showSnackBar(SnackBar( - content: Text('Something went wrong (HTTP ${response.statusCode})'))); + messenger.showSnackBar(SnackBar(content: Text('Something went wrong (HTTP ${response.statusCode})'))); } return null; } @@ -75,14 +67,12 @@ Future isLoggedIn(BuildContext context) async { final payload = jsonDecode(String.fromCharCodes(base64Decode(base64))); if (payload['exp'] < DateTime.now().millisecondsSinceEpoch / 1000) { - messenger.showSnackBar( - const SnackBar(content: Text('Token expired, please sign in again'))); + messenger.showSnackBar(const SnackBar(content: Text('Token expired, please sign in again'))); prefs.remove('token'); return false; } } catch (e) { - messenger.showSnackBar( - const SnackBar(content: Text('Invalid token, please sign in again'))); + messenger.showSnackBar(const SnackBar(content: Text('Invalid token, please sign in again'))); prefs.remove('token'); return false; } diff --git a/Mobile/lib/login.dart b/Mobile/lib/login.dart index 224b905..6f219b5 100644 --- a/Mobile/lib/login.dart +++ b/Mobile/lib/login.dart @@ -15,8 +15,7 @@ class _LoginPageState extends State { final passwordInput = TextEditingController(); Future _login() async { - final token = await api - .request(context, api.ApiService.auth, 'POST', '/api/Users/login', { + final token = await api.request(context, api.ApiService.auth, 'POST', '/api/Users/login', { 'email': emailInput.text, 'password': passwordInput.text, }); @@ -27,8 +26,7 @@ class _LoginPageState extends State { prefs.setString('token', token); if (mounted) { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Successfully logged in'))); + ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Successfully logged in'))); Navigator.pushReplacementNamed(context, '/home'); } } @@ -47,17 +45,18 @@ class _LoginPageState extends State { const SizedBox(height: 30), const Text('Password'), TextField( - controller: passwordInput, - obscureText: true, - enableSuggestions: false, - autocorrect: false), + controller: passwordInput, + obscureText: true, + enableSuggestions: false, + autocorrect: false, + ), const SizedBox(height: 30), ElevatedButton(onPressed: _login, child: const Text('Login')), const SizedBox(height: 10), TextButton( - child: const Text('Register account'), - onPressed: () => - Navigator.pushReplacementNamed(context, '/register')), + child: const Text('Register account'), + onPressed: () => Navigator.pushReplacementNamed(context, '/register') + ), ]), ), ),