added client token login

This commit is contained in:
hannathkadher
2025-04-16 12:02:19 +04:00
parent 7af61d2f65
commit dd66e7c747
4 changed files with 50 additions and 3 deletions

View File

@ -11,7 +11,7 @@ abstract class ApiEndpoints {
static const String sendOtp = '/authentication/user/send-otp';
static const String verifyOtp = '/authentication/user/verify-otp';
static const String forgetPassword = '/authentication/user/forget-password';
static const String clientLogin = 'client/token';
////////////////////////////////////// Spaces ///////////////////////////////////////
///Community Module

View File

@ -25,11 +25,15 @@ class AuthenticationAPI {
return response;
}
static Future<bool> signUp({required SignUpModel model}) async {
static Future<bool> signUp({
required SignUpModel model,
required String accessToken,
}) async {
final response = await HTTPService().post(
path: ApiEndpoints.signUp,
body: model.toJson(),
showServerMessage: false,
accessToken: accessToken,
expectedResponseModel: (json) => json['statusCode'] == 201);
return response;
}
@ -63,4 +67,20 @@ class AuthenticationAPI {
expectedResponseModel: (json) => json['data']);
return response;
}
static Future<Map<String, dynamic>> fetchClientToken({
required String clientId,
required String clientSecret,
}) async {
final response = await HTTPService().post(
path: ApiEndpoints.clientLogin,
body: {
'clientId': clientId,
'clientSecret': clientSecret,
},
showServerMessage: false,
expectedResponseModel: (json) => json['data'],
);
return response;
}
}

View File

@ -48,13 +48,26 @@ class HTTPService {
Options? options,
dynamic body,
bool showServerMessage = true,
String? accessToken,
required T Function(dynamic) expectedResponseModel}) async {
try {
final authOptions = options ??
Options(
headers: accessToken != null
? {
'Authorization': 'Bearer $accessToken',
'Content-Type': 'application/json',
}
: {
'Content-Type': 'application/json',
},
);
final response = await client.post(
path,
data: body,
queryParameters: queryParameters,
options: options,
options: authOptions,
);
return expectedResponseModel(response.data);
} catch (error) {