Skip to content
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

fix uncaught exception #913

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

updbqn
Copy link

@updbqn updbqn commented Jan 28, 2025

The check further down:

if (userId && !user) {
		console.info('something weird happened')
		// something weird happened... The user is authenticated but we can't find
		// them in the database. Maybe they were deleted? Let's log them out.
		await logout({ request, redirectTo: '/' })
}

relies on the query returning null rather than throwing.

As an aside, I'm not sure exactly when userId && !user could happen. If the user was deleted, the onDelete cascade on Session means the previous getUserId call would already have redirected and removed the session cookie.

@jacobparis
Copy link
Contributor

jacobparis commented Jan 29, 2025

As an aside, I'm not sure exactly when userId && !user could happen.

That's why it's prefaced with "something weird happened". What if the user was manually deleted in the database? what if there was an error in the onDelete and it never completed? This provides a graceful exit in cases like that

@updbqn
Copy link
Author

updbqn commented Jan 29, 2025

Sure, I get the reasoning. However, wouldn't the user have to disappear within milliseconds of the getUserId call for this to be an issue?

I think it's good to check our assumptions, but wouldn't it be better if we could do it once and be done with it? I would find that easier to read and reason about. I was hoping the aside might spark an idea for a cleaner approach.

Even further off-topic if it's interesting:

What if the user was manually deleted in the database?

I would expect this to trigger the onDelete cascade?

what if there was an error in the onDelete and it never completed?

I would expect the original delete and onDelete cascade to happen as one transaction and succeed or fail together?

Though I still agree that it's a good idea to try to handle weird states :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants