File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Changelog
22
3+ ## 1.9.0+1
4+
5+ ### Added
6+
7+ - LanguageInterceptor for all repositories
8+
39## 1.8.5+1
410
511### Fixed
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import "package:image_picker/image_picker.dart";
99import "package:path/path.dart" ;
1010import "package:supa_architecture/api_client/interceptors/device_info_interceptor.dart" ;
1111import "package:supa_architecture/api_client/interceptors/general_error_log_interceptor.dart" ;
12+ import "package:supa_architecture/api_client/interceptors/language_interceptor.dart" ;
1213import "package:supa_architecture/api_client/interceptors/persistent_url_interceptor.dart" ;
1314import "package:supa_architecture/api_client/interceptors/refresh_interceptor.dart" ;
1415import "package:supa_architecture/api_client/interceptors/timezone_interceptor.dart" ;
@@ -36,6 +37,7 @@ abstract class ApiClient {
3637 ApiClient ({
3738 bool shouldUsePersistentUrl = false ,
3839 bool shouldUseDeviceInfo = false ,
40+ bool shouldUseLanguage = true ,
3941 RefreshInterceptor ? refreshInterceptor,
4042 }) : dio = Dio () {
4143 if (refreshInterceptor != null ) {
@@ -48,6 +50,10 @@ abstract class ApiClient {
4850 dio.interceptors.add (DeviceInfoInterceptor ());
4951 }
5052
53+ if (shouldUseLanguage) {
54+ dio.interceptors.add (LanguageInterceptor ());
55+ }
56+
5157 if (! kIsWeb) {
5258 dio.interceptors
5359 .add (SupaArchitecturePlatform .instance.cookieStorage.interceptor);
Original file line number Diff line number Diff line change 1+ import 'package:dio/dio.dart' ;
2+ import 'package:get_it/get_it.dart' ;
3+ import 'package:supa_architecture/blocs/blocs.dart' ;
4+
5+ /// An interceptor that adds the language to the request headers.
6+ ///
7+ /// This interceptor is used to provide the language to the request headers,
8+ /// helping the backend identify the language of the request.
9+ class LanguageInterceptor extends Interceptor {
10+ @override
11+ void onRequest (RequestOptions options, RequestInterceptorHandler handler) {
12+ // Check if the authentication bloc is registered.
13+ if (GetIt .instance.isRegistered <AuthenticationBloc >()) {
14+ // Get the authentication bloc.
15+ final authenticationBloc = GetIt .instance.get <AuthenticationBloc >();
16+
17+ // Check if the user is authenticated.
18+ if (authenticationBloc.state.isAuthenticated) {
19+ // Get the language from the user.
20+ final language = (authenticationBloc.state
21+ as UserAuthenticatedWithSelectedTenantState )
22+ .user
23+ .language
24+ .value
25+ .code
26+ .value;
27+ if (language.isNotEmpty) {
28+ options.headers['X-Language' ] = language;
29+ }
30+ }
31+ }
32+ handler.next (options);
33+ }
34+ }
Original file line number Diff line number Diff line change 11name : supa_architecture
22description : Architecture library for Supa Flutter applications
3- version : 1.8.5 +1
3+ version : 1.9.0 +1
44homepage : https://github.supa.vn
55
66environment :
You can’t perform that action at this time.
0 commit comments