-
Notifications
You must be signed in to change notification settings - Fork 349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Server log out after delete #306
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
import { z } from "zod"; | ||
import { deleteContact as deleteLoopsContact } from "@inboxzero/loops"; | ||
import { deleteContact as deleteResendContact } from "@inboxzero/resend"; | ||
import { auth } from "@/app/api/auth/[...nextauth]/auth"; | ||
import { auth, signOut } from "@/app/api/auth/[...nextauth]/auth"; | ||
import prisma from "@/utils/prisma"; | ||
import { deleteInboxZeroLabels, deleteUserLabels } from "@/utils/redis/label"; | ||
import { deleteUserStats } from "@/utils/redis/stats"; | ||
|
@@ -66,10 +66,14 @@ export const deleteAccountAction = withActionInstrumentation( | |
}), | ||
]); | ||
} catch (error) { | ||
console.error("Error while deleting account: ", error); | ||
console.error("Error while deleting account:", error); | ||
captureException(error, undefined, session.user.email); | ||
} | ||
|
||
try { | ||
await signOut(); | ||
} catch (error) {} | ||
|
||
Comment on lines
+73
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Reorder signOut after user deletion The current implementation calls Also, the empty catch block should at least log the error to help with debugging. - try {
- await signOut();
- } catch (error) {}
-
await prisma.user.delete({ where: { email: session.user.email } });
+
+ try {
+ await signOut();
+ } catch (error) {
+ console.error("Error during sign out after account deletion:", error);
+ // Don't rethrow as the account is already deleted
+ } Also applies to: 78-78 |
||
await prisma.user.delete({ where: { email: session.user.email } }); | ||
}, | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider potential race conditions in the deletion flow.
The current implementation has a good flow with proper user feedback through toasts. However, there's a potential race condition between account deletion and logout. If the deletion succeeds but logout fails, the user might be left in an inconsistent state.
Consider wrapping both operations in a single try-catch: