@@ -5,13 +5,16 @@ import 'package:survey_flutter/di/provider/dio_provider.dart';
55import 'package:survey_flutter/env.dart' ;
66import 'package:survey_flutter/model/login_model.dart' ;
77import 'package:survey_flutter/model/request/login_request.dart' ;
8+ import 'package:survey_flutter/storage/secure_storage.dart' ;
9+ import 'package:survey_flutter/storage/secure_storage_impl.dart' ;
810
911const String _grantType = "password" ;
1012
1113final authenticationRepositoryProvider =
12- Provider <AuthenticationRepository >((_ ) {
14+ Provider <AuthenticationRepository >((ref ) {
1315 return AuthenticationRepositoryImpl (
1416 AuthenticationApiService (DioProvider ().getDio ()),
17+ ref.watch (secureStorageProvider),
1518 );
1619});
1720
@@ -24,8 +27,12 @@ abstract class AuthenticationRepository {
2427
2528class AuthenticationRepositoryImpl extends AuthenticationRepository {
2629 final AuthenticationApiService _authenticationApiService;
30+ final SecureStorage _secureStorage;
2731
28- AuthenticationRepositoryImpl (this ._authenticationApiService);
32+ AuthenticationRepositoryImpl (
33+ this ._authenticationApiService,
34+ this ._secureStorage,
35+ );
2936
3037 @override
3138 Future <LoginModel > login ({
@@ -40,6 +47,10 @@ class AuthenticationRepositoryImpl extends AuthenticationRepository {
4047 clientSecret: Env .clientSecret,
4148 grantType: _grantType,
4249 ));
50+ await _secureStorage.save (
51+ value: response.toApiToken (),
52+ key: SecureStorageKey .apiToken,
53+ );
4354 return response.toLoginModel ();
4455 } catch (exception) {
4556 throw NetworkExceptions .fromDioException (exception);
0 commit comments