mobile-app/lib/helper/AuthServices.dart

52 lines
1.3 KiB
Dart
Raw Permalink Normal View History

2024-10-21 12:33:46 +00:00
import 'dart:convert';
import 'package:http/http.dart' as http;
class AuthService {
final String baseUrl = 'http://10.0.2.2:50681/';
Future<Map<String, dynamic>> register(
String username, String password) async {
final response = await http.post(
Uri.parse('${baseUrl}register/'),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, String>{
'username': username,
'password': password,
}),
);
return jsonDecode(response.body);
}
Future<Map<String, dynamic>> login(String username, String password) async {
final response = await http.post(
Uri.parse('${baseUrl}auth/token/'),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, String>{
'username': username,
'password': password,
}),
);
return jsonDecode(response.body);
}
Future<Map<String, dynamic>> refreshToken(String refreshToken) async {
final response = await http.post(
Uri.parse('${baseUrl}token/refresh/'),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, String>{
'refresh': refreshToken,
}),
);
return jsonDecode(response.body);
}
}