forked from baron/baron-sso
Merge branch 'dev/qr'
This commit is contained in:
@@ -70,9 +70,16 @@ final _router = GoRouter(
|
||||
refreshListenable: AuthNotifier.instance,
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
path: '/',
|
||||
builder: (context, state) {
|
||||
_routerLogger.info("Navigating to root (LoginScreen)");
|
||||
_routerLogger.info("Navigating to root (DashboardScreen)");
|
||||
return const DashboardScreen();
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: '/login',
|
||||
builder: (context, state) {
|
||||
_routerLogger.info("Navigating to /login");
|
||||
return const LoginScreen();
|
||||
}
|
||||
),
|
||||
@@ -92,13 +99,6 @@ final _router = GoRouter(
|
||||
return ApproveQrScreen(pendingRef: ref);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: '/dashboard',
|
||||
builder: (context, state) {
|
||||
_routerLogger.info("Navigating to /dashboard");
|
||||
return const DashboardScreen();
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: '/scan',
|
||||
builder: (context, state) {
|
||||
@@ -118,17 +118,29 @@ final _router = GoRouter(
|
||||
final isLoggedIn =
|
||||
Descope.sessionManager.session?.refreshToken?.isExpired == false;
|
||||
final path = state.uri.path;
|
||||
final isLoggingIn = path == '/' || path.startsWith('/verify/') || path == '/approve';
|
||||
|
||||
// Public paths that don't require login
|
||||
final isPublicPath = path == '/login' ||
|
||||
path.startsWith('/verify/') ||
|
||||
path == '/approve';
|
||||
|
||||
_routerLogger.fine("Redirect check - Path: $path, IsLoggedIn: $isLoggedIn");
|
||||
|
||||
if (!isLoggedIn && !isLoggingIn) {
|
||||
_routerLogger.info("Not logged in, redirecting to /");
|
||||
return '/';
|
||||
// 0. ALWAYS allow /verify/ to proceed so it can signal the backend
|
||||
if (path.startsWith('/verify/')) {
|
||||
return null;
|
||||
}
|
||||
if (isLoggedIn && path == '/') {
|
||||
_routerLogger.info("Logged in, redirecting to /dashboard");
|
||||
return '/dashboard';
|
||||
|
||||
// If not logged in and trying to access a protected page, redirect to /login
|
||||
if (!isLoggedIn && !isPublicPath) {
|
||||
_routerLogger.info("Not logged in, redirecting to /login");
|
||||
return '/login';
|
||||
}
|
||||
|
||||
// If logged in and trying to access login page, redirect to root (dashboard)
|
||||
if (isLoggedIn && path == '/login') {
|
||||
_routerLogger.info("Logged in, redirecting to /");
|
||||
return '/';
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user