forked from baron/baron-sso
로그인 url path 방식 수정
This commit is contained in:
@@ -4,11 +4,13 @@ import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:descope/descope.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:flutter_web_plugins/url_strategy.dart';
|
||||
import 'features/auth/presentation/login_screen.dart';
|
||||
import 'features/dashboard/presentation/dashboard_screen.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
usePathUrlStrategy();
|
||||
|
||||
// Load Env (Handling error if missing for now)
|
||||
try {
|
||||
@@ -36,6 +38,13 @@ final _router = GoRouter(
|
||||
initialLocation: '/',
|
||||
routes: [
|
||||
GoRoute(path: '/', builder: (context, state) => const LoginScreen()),
|
||||
GoRoute(
|
||||
path: '/verify/:token',
|
||||
builder: (context, state) {
|
||||
final token = state.pathParameters['token'];
|
||||
return LoginScreen(verificationToken: token);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: '/dashboard',
|
||||
builder: (context, state) => const DashboardScreen(),
|
||||
@@ -44,10 +53,11 @@ final _router = GoRouter(
|
||||
redirect: (context, state) {
|
||||
final isLoggedIn =
|
||||
Descope.sessionManager.session?.refreshToken.isExpired == false;
|
||||
final isLoggingIn = state.uri.toString() == '/';
|
||||
final path = state.uri.path;
|
||||
final isLoggingIn = path == '/' || path.startsWith('/verify/');
|
||||
|
||||
if (!isLoggedIn && !isLoggingIn) return '/';
|
||||
if (isLoggedIn && isLoggingIn) return '/dashboard';
|
||||
if (isLoggedIn && path == '/') return '/dashboard';
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user