Skip to content

Commit 429d891

Browse files
committed
v1.9.0+1
1 parent 0e61ef8 commit 429d891

4 files changed

Lines changed: 47 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
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

lib/api_client/api_client.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import "package:image_picker/image_picker.dart";
99
import "package:path/path.dart";
1010
import "package:supa_architecture/api_client/interceptors/device_info_interceptor.dart";
1111
import "package:supa_architecture/api_client/interceptors/general_error_log_interceptor.dart";
12+
import "package:supa_architecture/api_client/interceptors/language_interceptor.dart";
1213
import "package:supa_architecture/api_client/interceptors/persistent_url_interceptor.dart";
1314
import "package:supa_architecture/api_client/interceptors/refresh_interceptor.dart";
1415
import "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);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: supa_architecture
22
description: Architecture library for Supa Flutter applications
3-
version: 1.8.5+1
3+
version: 1.9.0+1
44
homepage: https://github.supa.vn
55

66
environment:

0 commit comments

Comments
 (0)