server/lib/apis/auth.dart
2025-05-27 09:48:44 +03:00

41 lines
1.1 KiB
Dart

import 'package:dio/dio.dart';
import 'package:server/constants.dart';
import 'package:server/server.dart';
class Auth {
String lastError = '';
login(String email, String password) async {
try {
final response = await api.post(
'/collections/users/auth-with-password',
data: {identityKey: email, passwordKey: password},
);
return response.data;
} on DioException catch (e) {
if (e.type == DioExceptionType.connectionError) {
lastError = 'Internet Connection Error';
} else {
lastError = e.response!.data['message'];
}
}
}
register(String email, String password) async {
try {
final response = await api.post(
'/collections/users/records',
data: {emailKey: email, passwordKey: password},
);
return response.data;
} on DioException catch (e) {
if (e.type == DioExceptionType.connectionError) {
lastError = 'Internet Connection Error';
} else {
lastError = e.response!.data['message'];
}
}
}
}
final auth = Auth();