Skip to content

Commit

Permalink
fix(token verification): check token validity (#1195)
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentMag authored Jan 3, 2024
1 parent 631047a commit 7aa61ed
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion yaki_mobile/lib/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:yaki/presentation/features/user_declaration_summary/user_declara
import 'package:yaki/presentation/features/team_selection/team_selection.dart';
import 'package:yaki/presentation/features/user_declaration_summary/user_declaration_summary_absence.dart';
import 'package:yaki/presentation/state/providers/declaration_provider.dart';
import 'package:yaki/presentation/state/providers/token_provider.dart';
import 'package:yaki/presentation/ui/default/user_default_redirection.dart';
import 'package:yaki/presentation/features/password/forgot_password.dart';
import 'package:yaki/presentation/features/password/change_password.dart';
Expand All @@ -31,7 +32,17 @@ final goRouterProvider = Provider<GoRouter>(
// only redirect if we are on the Splash Screen
if (state.fullPath == '/') {
SharedPreferences prefs = await SharedPreferences.getInstance();

final isJWTValid =
await ref.read(tokenRepositoryProvider).verifyTokenValidity();

if (!isJWTValid) {
prefs.remove('token');
return '/authentication';
}

final declaration = ref.watch(declarationProvider);

bool isLoggedIn = prefs.containsKey('token');
final latestDeclarationStatus =
declaration.latestDeclarationStatus;
Expand Down Expand Up @@ -65,7 +76,9 @@ final goRouterProvider = Provider<GoRouter>(
child: Authentication(),
),
redirect: (BuildContext context, GoRouterState state) async {
if (await SharedPref.isTokenPresent()) {
final isTokenSaves = await SharedPref.isTokenPresent();

if (isTokenSaves) {
return '/teams-declaration-summary';
} else {
return '/authentication';
Expand Down

0 comments on commit 7aa61ed

Please sign in to comment.