mirror of
https://github.com/R0m1k3/xtremflow.git
synced 2026-10-20 21:48:06 +02:00
feat: Add initial backend server with user authentication, session management, and playlist CRUD functionality.
This commit is contained in:
1 parent
a1ce183cd3
commit
ac4f274031
19 files changed
+1324
-75
No files matched your search
@@ -9,15 +9,20 @@ import '../../features/admin/screens/admin_panel.dart';
|
||||
import '../models/playlist_config.dart';
|
||||
|
||||
final routerProvider = Provider<GoRouter>((ref) {
|
||||
final authNotifier = ref.watch(authProvider.notifier);
|
||||
final authState = ref.watch(authProvider);
|
||||
|
||||
return GoRouter(
|
||||
initialLocation: '/login',
|
||||
refreshListenable: RouterRefreshNotifier(ref),
|
||||
redirect: (context, state) {
|
||||
final isLoggedIn = authState.isAuthenticated;
|
||||
final isLoginRoute = state.matchedLocation == '/login';
|
||||
|
||||
// Wait for initial auth check to complete
|
||||
if (!authState.isInitialized) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Redirect to login if not authenticated
|
||||
if (!isLoggedIn && !isLoginRoute) {
|
||||
return '/login';
|
||||
@@ -67,3 +72,14 @@ final routerProvider = Provider<GoRouter>((ref) {
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
/// Notifier that triggers router refresh when auth state changes
|
||||
class RouterRefreshNotifier extends ChangeNotifier {
|
||||
RouterRefreshNotifier(this._ref) {
|
||||
_ref.listen(authProvider, (_, __) {
|
||||
notifyListeners();
|
||||
});
|
||||
}
|
||||
|
||||
final Ref _ref;
|
||||
}
|
||||
Reference in new issue
Block a user