Current section: Logout 6 exercises

Destroying Sessions and Handling Weird States

Loading solution


00:00 I'm going to leave everything up as it was, where we have this session that doesn't have a user ID in it anymore. When I'm done, we should see this session getting destroyed. Let's go to our root and we'll come right here and we'll say, if there's a user ID, but there's not a user,

00:18 then that's where we're in that weird spot. We're going to return a redirect to, and actually let's throw so we don't have issues with TypeScript or whatever. We'll just throw a redirect to our home. Here's our headers, headers, where we're going to say set cookie.

00:36 This is await session storage and destroy session. Here's our cookie session. Yeah, that should do it. Let's grab a redirect from remix run node, save that, and that cookie is gone now. We no longer have this problem. Let's just redo the whole process again just to make

00:56 sure that this problem really is gone. I'll log in as this user and log in. Now, we'll scooch this up just a bit so we can see that we've got that in session right there. Come find that user in here and delete that record. That user is gone. I hit refresh,

01:15 and now that cookie is gone as well. In review, it's actually basically just the same thing we did, destroy a session, and that session is now gone. The cookie is gone. We do that when we get into these weird states. There you go.