Skip to content

Commit

Permalink
Admin UI: Encountering infinite loading when accessing pages while lo…
Browse files Browse the repository at this point in the history
…gged out (#842)

* fix: make redirect to login screen when not authenticated

* fix; navigate to correct page after login

* fix: simplify navigate and change default to login

* chore: remove method and add redirect when user is authenticated

* fix: make it an arrow function

* fix: make an early return

* chore: remove unnecessary return keyword
  • Loading branch information
stamenione authored Sep 5, 2024
1 parent 3684bd6 commit e63dd52
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,22 @@ class _SplashScreenState extends State<SplashScreen> {
await GetIt.I.allReady();
final sp = await SharedPreferences.getInstance();

if (!sp.containsKey('api_key')) return _navigate('/login');
if (!sp.containsKey('api_key')) return _navigateToLogin();

final apiKey = sp.getString('api_key')!;
const baseUrl = kIsWeb ? '' : String.fromEnvironment('base_url');

final isValid = await AdminApiClient.validateApiKey(baseUrl: baseUrl, apiKey: apiKey);
if (!isValid) return _navigate('/login');
if (!isValid) return _navigateToLogin();

GetIt.I.registerSingleton(await AdminApiClient.create(baseUrl: baseUrl, apiKey: apiKey));
return _navigate('/identities');
}

void _navigate(String defaultRoute) {
if (!mounted) return;

if (widget.redirect != null) return context.go(Uri.decodeComponent(widget.redirect!));

context.go(defaultRoute);
context.go('/identities');
}

void _navigateToLogin() => context.go(widget.redirect != null ? '/login?redirect=${widget.redirect!}' : '/login');
}

0 comments on commit e63dd52

Please sign in to comment.