Integrating User Sessions into the Login Process
00:00 So let's get into our schema. We'll come down here, yeah, right around here with the sessions. So it's going to be a pretty typical model. We'll say model session, and this is going to have all the typical stuff. So Copilot can do it. We've got the ID, the expiration date. So that is a date time,
00:18 that's when this thing expires. In the future, we can add a cron job that will just delete old sessions from the database automatically. These will get deleted when we log out and other things too, but they could expire and then they're just like sitting in the database for no good reason. So you could delete these after that expiration date. And yeah, then we have created that, updated that,
00:38 and then we have our relationship to the user. So based on the user ID that we have here, it's going to reference the ID that's in the user model up here, that ID. And then when that user is deleted, we'll cascade that or updated, we'll cascade that to this model.
00:57 And that, that is that. So if I save this again, the Prisma extension is going to update all of this stuff for me. So the red lines go away, but it's also going to name this session with capital. I don't understand why it does that. We're going to do sessions with an S.
01:14 And so now we have all of the users sessions associated to the user. So what we can do now is do our migration. And we'll say npx prisma migrate dev. And we'll just call this sessions. And there we are, we generated our clients, all that stuff is good.
01:32 So now if we go to download user data and we come down here and we'll say, yeah, we definitely don't want to send a long password. We'll say the session, whoops, session is true. We want to download the session. And with that, we've got our user sessions all ready to go in the database and ready to download.
01:52 Now we just need to integrate it with our login process. So that's what's up next.