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

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:syncrow_app/features/auth/model/login_with_email_model.dart';
import 'package:syncrow_app/features/auth/model/signup_model.dart';
@ -217,9 +218,22 @@ class AuthCubit extends Cubit<AuthState> {
signUp() async {
emit(AuthLoginLoading());
final response;
final clientId = dotenv.env['CLIENT_ID'] ?? '';
final clientSecret = dotenv.env['CLIENT_SECRET'] ?? '';
try {
List<String> userFullName = fullName.split(' ');
final clientToken = await AuthenticationAPI.fetchClientToken(
clientId: clientId,
clientSecret: clientSecret,
);
final accessToken = clientToken['accessToken'];
response = await AuthenticationAPI.signUp(
accessToken: accessToken,
model: SignUpModel(
hasAcceptedAppAgreement: true,
email: email.toLowerCase(),

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) {