feat: Add initial backend server with user authentication, session management, and playlist CRUD functionality.

This commit is contained in:
Michael committed 2025-12-06 01:51:07 +01:00
1 parent a1ce183cd3
commit ac4f274031
19 files changed
+1324 -75

No files matched your search

+17 -1
View File
@@ -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;
}