fix: clear all data on logout
This commit is contained in:
@@ -318,8 +318,12 @@ class UserProfileProvider extends ChangeNotifier {
|
||||
|
||||
try {
|
||||
await _storageService!.clearUserData();
|
||||
|
||||
// Clear user-specific provider state but keep services for future sign-ins
|
||||
_home = null;
|
||||
_currentUser = null;
|
||||
_onDataInvalidationRequested = null;
|
||||
|
||||
_clearError();
|
||||
notifyListeners();
|
||||
|
||||
|
||||
@@ -210,8 +210,13 @@ class _DiscoverScreenState extends State<DiscoverScreen>
|
||||
);
|
||||
|
||||
if (confirm == true && mounted) {
|
||||
final storage = await StorageService.getInstance();
|
||||
await storage.clearCredentials();
|
||||
// Use comprehensive logout through UserProfileProvider
|
||||
final userProfileProvider = Provider.of<UserProfileProvider>(context, listen: false);
|
||||
final plexClientProvider = Provider.of<PlexClientProvider>(context, listen: false);
|
||||
|
||||
// Clear all user data and provider states
|
||||
await userProfileProvider.logout();
|
||||
plexClientProvider.clearClient();
|
||||
|
||||
if (mounted) {
|
||||
Navigator.of(context).pushAndRemoveUntil(
|
||||
|
||||
@@ -45,11 +45,13 @@ class _MainScreenState extends State<MainScreen> with RouteAware {
|
||||
];
|
||||
|
||||
// Set up data invalidation callback for profile switching
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
context.userProfile.setDataInvalidationCallback(_invalidateAllScreens);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
// Initialize UserProfileProvider to ensure it's ready after sign-in
|
||||
final userProfileProvider = context.userProfile;
|
||||
await userProfileProvider.initialize();
|
||||
|
||||
// Set the client in the provider so profile switching can update its token
|
||||
context.plexClient.setClient(widget.client);
|
||||
// Set up data invalidation callback for profile switching
|
||||
userProfileProvider.setDataInvalidationCallback(_invalidateAllScreens);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import '../services/server_connection_service.dart';
|
||||
import '../widgets/server_list_tile.dart';
|
||||
import '../widgets/desktop_app_bar.dart';
|
||||
import '../utils/app_logger.dart';
|
||||
import '../utils/provider_extensions.dart';
|
||||
import 'main_screen.dart';
|
||||
|
||||
class ServerSelectionScreen extends StatefulWidget {
|
||||
@@ -139,8 +140,11 @@ class _ServerSelectionScreenState extends State<ServerSelectionScreen> {
|
||||
|
||||
// Handle result
|
||||
if (result.isSuccess) {
|
||||
// Navigate to main app and clear navigation stack
|
||||
// Set client in provider before navigation (same pattern as auto-login)
|
||||
if (mounted) {
|
||||
context.plexClient.setClient(result.client!);
|
||||
|
||||
// Navigate to main app and clear navigation stack
|
||||
Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
|
||||
@@ -120,6 +120,9 @@ class StorageService {
|
||||
_prefs.remove(_keyServerData),
|
||||
_prefs.remove(_keyClientId),
|
||||
_prefs.remove(_keyUserProfile),
|
||||
_prefs.remove(_keyCurrentUserUUID),
|
||||
_prefs.remove(_keyHomeUsersCache),
|
||||
_prefs.remove(_keyHomeUsersCacheExpiry),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -240,9 +243,6 @@ class StorageService {
|
||||
await Future.wait([
|
||||
clearCredentials(),
|
||||
clearLibraryPreferences(),
|
||||
_prefs.remove(_keyUserProfile),
|
||||
_prefs.remove(_keyCurrentUserUUID),
|
||||
clearHomeUsersCache(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -111,9 +111,7 @@ ThemeData monoTheme({required bool dark}) {
|
||||
elevation: const WidgetStatePropertyAll(0),
|
||||
backgroundColor: WidgetStatePropertyAll(c.text),
|
||||
foregroundColor: WidgetStatePropertyAll(dark ? c.bg : Colors.white),
|
||||
shape: WidgetStatePropertyAll(
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
),
|
||||
shape: const WidgetStatePropertyAll(StadiumBorder()),
|
||||
),
|
||||
),
|
||||
filledButtonTheme: FilledButtonThemeData(
|
||||
@@ -124,9 +122,7 @@ ThemeData monoTheme({required bool dark}) {
|
||||
elevation: const WidgetStatePropertyAll(0),
|
||||
backgroundColor: WidgetStatePropertyAll(c.text),
|
||||
foregroundColor: WidgetStatePropertyAll(dark ? c.bg : Colors.white),
|
||||
shape: WidgetStatePropertyAll(
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
),
|
||||
shape: const WidgetStatePropertyAll(StadiumBorder()),
|
||||
),
|
||||
),
|
||||
dividerTheme: DividerThemeData(space: 0, thickness: 1, color: c.outline),
|
||||
|
||||
Reference in New Issue
Block a user