Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Hoàng Văn Đạt
mypoint_flutter_app
Commits
9bb8aadd
Commit
9bb8aadd
authored
Oct 22, 2025
by
DatHV
Browse files
update
parent
0bf528a4
Changes
4
Show whitespace changes
Inline
Side-by-side
export_web.sh
View file @
9bb8aadd
...
...
@@ -9,6 +9,10 @@ echo "🚀 Exporting Flutter web app for production..."
echo
"🛑 Stopping any existing server on :8080..."
lsof
-i
:8080 |
awk
'NR>1 {print $2}'
| xargs
kill
-9
2>/dev/null
||
true
# Switch to PRO environment automatically
echo
"🔧 Switching to PRO environment..."
./scripts/switch_env.sh prod
# Clear cache build để tránh dính SW/cache cũ
echo
"🧹 Clearing build caches..."
flutter clean
...
...
lib/configs/api_paths.dart
View file @
9bb8aadd
...
...
@@ -14,6 +14,7 @@ class APIPaths {//sandbox
static
const
String
otpVerifyForDoingNextEvent
=
"/otpVerifyForDoingNextEvent/1.0.0"
;
static
const
String
accountPasswordReset
=
"/accountPasswordReset/1.0.0"
;
static
const
String
login
=
"/iam/v1/authentication/account-login"
;
static
const
String
logout
=
"/accountLogout/1.0.0"
;
static
const
String
loginWithBiometric
=
"/iam/v1/authentication/bio-login"
;
static
const
String
getUserInfo
=
"/user/api/v2.0/mypoint/me"
;
static
const
String
refreshToken
=
"/accountAccessTokenRefresh/3.0.0"
;
...
...
lib/main.dart
View file @
9bb8aadd
...
...
@@ -3,6 +3,7 @@ import 'package:flutter_localizations/flutter_localizations.dart';
import
'package:get/get.dart'
;
import
'package:mypoint_flutter_app/base/app_navigator.dart'
;
import
'package:mypoint_flutter_app/resources/base_color.dart'
;
import
'package:mypoint_flutter_app/screen/splash/splash_screen.dart'
;
import
'package:mypoint_flutter_app/shared/router_gage.dart'
;
import
'package:mypoint_flutter_app/core/app_initializer.dart'
;
...
...
@@ -28,7 +29,7 @@ class MyApp extends StatelessWidget {
navigatorKey:
AppNavigator
.
key
,
navigatorObservers:
[
routeObserver
],
debugShowCheckedModeBanner:
false
,
initialRoute:
'/splash'
,
//
initialRoute: '/splash',
theme:
ThemeData
(
colorScheme:
ColorScheme
.
fromSwatch
(
primarySwatch:
Colors
.
brown
),
primaryColor:
BaseColor
.
primary500
,
...
...
@@ -42,7 +43,7 @@ class MyApp extends StatelessWidget {
GlobalWidgetsLocalizations
.
delegate
,
GlobalCupertinoLocalizations
.
delegate
,
],
//
home: SplashScreen(),
home:
SplashScreen
(),
getPages:
RouterPage
.
pages
(),
);
}
...
...
lib/networking/interceptor/auth_interceptor.dart
View file @
9bb8aadd
import
'package:dio/dio.dart'
;
import
'../../configs/api_paths.dart'
;
import
'../../configs/constants.dart'
;
import
'../../base/app_navigator.dart'
;
import
'../dio_http_service.dart'
;
...
...
@@ -9,11 +10,36 @@ class AuthInterceptor extends Interceptor {
bool
_isHandlingAuth
=
false
;
static
const
_kAuthHandledKey
=
'__auth_handled__'
;
// Danh sách các path không cần refresh token khi gặp lỗi auth
static
final
List
<
String
>
_skipRefreshTokenPaths
=
[
APIPaths
.
getUserInfo
,
APIPaths
.
login
,
APIPaths
.
refreshToken
,
APIPaths
.
logout
,
];
@override
Future
<
void
>
onResponse
(
Response
response
,
ResponseInterceptorHandler
handler
)
async
{
final
data
=
response
.
data
;
if
(
_isTokenInvalid
(
data
))
{
response
.
requestOptions
.
extra
[
_kAuthHandledKey
]
=
true
;
// Kiểm tra xem path này có cần skip refresh token không
if
(
_shouldSkipRefreshToken
(
response
.
requestOptions
.
path
))
{
handler
.
reject
(
DioException
(
requestOptions:
response
.
requestOptions
..
extra
[
'mapped_error'
]
=
ErrorCodes
.
tokenInvalidMessage
,
response:
response
,
type:
DioExceptionType
.
badResponse
,
error:
'ERR_AUTH_TOKEN_INVALID'
,
message:
ErrorCodes
.
tokenInvalidMessage
,
),
);
return
;
}
await
_handleAuthError
(
data
);
handler
.
reject
(
DioException
(
...
...
@@ -35,7 +61,16 @@ class AuthInterceptor extends Interceptor {
final
alreadyHandled
=
err
.
requestOptions
.
extra
[
_kAuthHandledKey
]
==
true
;
final
data
=
err
.
response
?.
data
;
final
statusCode
=
err
.
response
?.
statusCode
;
if
(
alreadyHandled
)
return
;
// Kiểm tra xem path này có cần skip refresh token không
if
(
_shouldSkipRefreshToken
(
err
.
requestOptions
.
path
)
&&
(
statusCode
==
401
||
statusCode
==
403
||
_isTokenInvalid
(
data
)))
{
handler
.
next
(
err
);
return
;
}
if
(
statusCode
==
401
||
_isTokenInvalid
(
data
))
{
await
_handleAuthError
(
data
,
originalRequest:
err
.
requestOptions
,
handler:
handler
,
originalError:
err
);
return
;
...
...
@@ -51,6 +86,22 @@ class AuthInterceptor extends Interceptor {
return
false
;
}
/// Kiểm tra xem path này có cần skip refresh token không
bool
_shouldSkipRefreshToken
(
String
path
)
{
print
(
'🔍 Checking if path should skip refresh token:
$path
'
);
if
(
path
.
isEmpty
)
return
false
;
print
(
'🔍 Cleaned path:
$path
'
);
// Kiểm tra xem path có chứa bất kỳ pattern nào trong danh sách skip không
for
(
String
skipPath
in
_skipRefreshTokenPaths
)
{
if
(
path
.
contains
(
skipPath
))
{
print
(
'🔍 Path "
$path
" matches skip pattern "
$skipPath
", skipping refresh token.'
);
return
true
;
}
}
print
(
'🔍 Path "
$path
" does not match any skip patterns, will attempt refresh token if needed.'
);
return
false
;
}
Future
<
void
>
_handleAuthError
(
dynamic
data
,
{
RequestOptions
?
originalRequest
,
ErrorInterceptorHandler
?
handler
,
DioException
?
originalError
})
async
{
if
(
_isHandlingAuth
)
return
;
_isHandlingAuth
=
true
;
...
...
@@ -99,4 +150,19 @@ class AuthInterceptor extends Interceptor {
}
await
AppNavigator
.
showAuthAlertAndGoLogin
(
message
??
ErrorCodes
.
tokenInvalidMessage
);
}
/// Thêm path vào danh sách skip refresh token
static
void
addSkipPath
(
String
path
)
{
if
(!
_skipRefreshTokenPaths
.
contains
(
path
))
{
_skipRefreshTokenPaths
.
add
(
path
);
}
}
/// Xóa path khỏi danh sách skip refresh token
static
void
removeSkipPath
(
String
path
)
{
_skipRefreshTokenPaths
.
remove
(
path
);
}
/// Lấy danh sách các path đang skip refresh token
static
List
<
String
>
get
skipPaths
=>
List
.
unmodifiable
(
_skipRefreshTokenPaths
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment