Add login page and implement session redirection on authentication
This commit is contained in:
@@ -12,6 +12,8 @@ import 'pages/file_explorer.dart';
|
||||
import 'pages/document_viewer.dart';
|
||||
import 'pages/editor_page.dart';
|
||||
import 'pages/join_page.dart';
|
||||
import 'pages/login_page.dart';
|
||||
import 'blocs/session/session_state.dart';
|
||||
import 'pages/public_file_viewer.dart';
|
||||
import 'theme/app_theme.dart';
|
||||
import 'injection.dart';
|
||||
@@ -22,6 +24,7 @@ final GoRouter _router = GoRouter(
|
||||
initialLocation: kIsWeb ? Uri.base.path : '/',
|
||||
routes: [
|
||||
GoRoute(path: '/', builder: (context, state) => const HomePage()),
|
||||
GoRoute(path: '/login', builder: (context, state) => const LoginPage()),
|
||||
GoRoute(
|
||||
path: '/viewer/:orgId/:fileId',
|
||||
builder: (context, state) => DocumentViewer(
|
||||
@@ -122,6 +125,19 @@ class _MainAppState extends State<MainApp> {
|
||||
return MaterialApp.router(
|
||||
routerConfig: _router,
|
||||
theme: AppTheme.darkTheme,
|
||||
builder: (context, child) {
|
||||
return BlocListener<SessionBloc, SessionState>(
|
||||
listener: (context, state) {
|
||||
if (state is SessionExpiredState) {
|
||||
final currentLocation = GoRouterState.of(
|
||||
context,
|
||||
).uri.toString();
|
||||
context.go('/login?redirect=$currentLocation');
|
||||
}
|
||||
},
|
||||
child: child!,
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
@@ -133,7 +133,10 @@ class _LoginFormState extends State<LoginForm> {
|
||||
_handleRegistration(context, state);
|
||||
} else if (state is AuthAuthenticated) {
|
||||
context.read<SessionBloc>().add(SessionStarted(state.token));
|
||||
context.go('/');
|
||||
final redirect = GoRouterState.of(
|
||||
context,
|
||||
).uri.queryParameters['redirect'];
|
||||
context.go(redirect ?? '/');
|
||||
}
|
||||
},
|
||||
child: Center(
|
||||
|
||||
27
b0esche_cloud/lib/pages/login_page.dart
Normal file
27
b0esche_cloud/lib/pages/login_page.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import './login_form.dart';
|
||||
|
||||
class LoginPage extends StatelessWidget {
|
||||
const LoginPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [Color(0xFF1a1a2e), Color(0xFF16213e), Color(0xFF0f3460)],
|
||||
),
|
||||
),
|
||||
child: const Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: LoginForm(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user