- Updated Android Gradle plugin version to 8.2.1 - Added new entries to .gitignore for better file management - Changed dummy email and password in LoginController for testing - Updated AuthService to handle login via API with improved error handling - Modified User model to use username instead of email - Enhanced login screen UI with better structure and design - Registered new plugins in GeneratedPluginRegistrant.swift - Updated package versions in pubspec.yaml and pubspec.lock
32 lines
1.0 KiB
Dart
32 lines
1.0 KiB
Dart
import 'dart:convert';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:marco/helpers/services/storage/local_storage.dart';
|
|
|
|
class AuthService {
|
|
static bool isLoggedIn = false;
|
|
|
|
static Future<Map<String, String>?> loginUser(
|
|
Map<String, dynamic> data) async {
|
|
try {
|
|
final response = await http.post(
|
|
Uri.parse('https://api.marcoaiot.com/api/auth/login'),
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: jsonEncode(data),
|
|
);
|
|
|
|
if (response.statusCode == 200) {
|
|
isLoggedIn = true;
|
|
await LocalStorage.setLoggedInUser(true);
|
|
// You can also store the user details in local storage if needed
|
|
return null; // No error, login successful
|
|
} else if (response.statusCode == 401) {
|
|
return {"password": "Invalid email or password"};
|
|
} else {
|
|
return {"error": "Something went wrong. Please try again."};
|
|
}
|
|
} catch (e) {
|
|
return {"error": "Network error. Please check your connection."};
|
|
}
|
|
}
|
|
}
|