fix: invalid auth loop due to missing refesh token

This commit is contained in:
haritabh-z01 2025-11-30 23:07:28 +05:30
parent a663578c25
commit 9dc5aac5fd
4 changed files with 24 additions and 12 deletions

View file

@ -226,12 +226,12 @@ export default function AdvancedSettingsPage() {
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
<Button
variant="destructive"
onClick={() => resetAppMutation.mutate()}
>
Yes, delete everything
</AlertDialogAction>
</Button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>

View file

@ -41,7 +41,7 @@ root.render(
<OnboardingErrorBoundary>
<App />
</OnboardingErrorBoundary>
<Toaster />
<Toaster position="top-right" />
</ThemeProvider>
</QueryClientProvider>
</api.Provider>

View file

@ -320,8 +320,13 @@ export class AuthService extends EventEmitter {
}
const authState = await this.getAuthState();
if (!authState || !authState.refreshToken) {
// No refresh token available - invalid state, logout user
if (!authState) {
// User was never logged in - nothing to refresh
return;
}
if (!authState.refreshToken) {
// User has auth state but no refresh token - corrupted state, logout
await this.logout();
return;
}

View file

@ -633,17 +633,24 @@ export const settingsRouter = createRouter({
logger.main.info("Resetting app - deleting all data");
}
// Close database connection before deleting the file
if (logger) {
logger.main.info("Closing database connection before reset");
}
// Close database connection before deleting
await closeDatabase();
// Add a small delay to ensure the connection is fully closed on Windows
await new Promise((resolve) => setTimeout(resolve, 100));
// Delete the database file
await fs.unlink(dbPath);
// Delete entire userData directory (includes db, models, cache, etc.)
const userDataPath = app.getPath("userData");
await fs.rm(userDataPath, { recursive: true, force: true });
// In development, also delete the local db file if it exists
if (process.env.NODE_ENV === "development" || !app.isPackaged) {
try {
await fs.unlink(dbPath);
} catch {
// Ignore if file doesn't exist
}
}
// Handle restart differently in development vs production
if (process.env.NODE_ENV === "development" || !app.isPackaged) {