feat: refactor code
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import '../../../../../core/storage/token_storage.dart';
|
||||
|
||||
/// ذخیرهی محلیِ توکن احراز هویت.
|
||||
class AuthLocalData {
|
||||
final TokenStorage _storage;
|
||||
AuthLocalData(this._storage);
|
||||
|
||||
Future<void> saveToken(String token) => _storage.write(token);
|
||||
Future<String?> readToken() => _storage.read();
|
||||
Future<void> clearToken() => _storage.clear();
|
||||
|
||||
Future<bool> hasToken() async {
|
||||
final t = await _storage.read();
|
||||
return t != null && t.isNotEmpty;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../../../../core/locator/locator.dart';
|
||||
import '../../../../../core/network/api_provider_imp.dart';
|
||||
|
||||
/// تماسهای خامِ HTTP مربوط به احراز هویت (خروجی Response).
|
||||
class AuthApiProvider {
|
||||
ApiProviderImp get _api => locator<ApiProviderImp>();
|
||||
|
||||
Future<Response> loginOtp(String mobile) =>
|
||||
_api.post('/auth/login-otp', body: {'mobile': mobile});
|
||||
|
||||
Future<Response> checkOtp(String mobile, String token) =>
|
||||
_api.post('/auth/check-otp', body: {'mobile': mobile, 'token': token});
|
||||
|
||||
Future<Response> updateProfile(String firstName, String avatar) =>
|
||||
_api.post('/profile', body: {'first_name': firstName, 'avatar': avatar});
|
||||
|
||||
Future<Response> me() => _api.get('/me');
|
||||
}
|
||||
Reference in New Issue
Block a user