Current section: Permissions 6 exercises

Managing Roles and Permissions

Loading exercise


00:00 Now that we have our database ready to have permissions and roles, we need to make sure we create new users with the proper role. We also actually have some users that are seated in the database, that they should probably have a proper role, like Cody should probably have both the user and admin role. For example, the generated users we have,

00:18 they should probably all have the user role. But things get a little bit tricky here because this is data that we need to assume is in the database already, even in production. With the seed script, we're generating that for local development, but we don't run that seed script in production.

00:37 We need to make sure that we seed the database with all the stuff we expect to be there when new users are created. That means we're going to need to have permissions and roles. There are a couple of things you're going to be doing in here. We want to have permissions and roles that are related to the user themselves and their notes and various other things.

00:56 You're going to need to make a bunch of different permissions for all of those, and then you'll make two roles, a user role and an admin role that have those permissions, so that in the seed script, we can update that to apply those roles appropriately. Then we'll also update the signup or onboarding flow,

01:15 so that we create new users with that role as well. There are a couple of things that are going on here. The trickiest bit here will be updating the migration that we just created with some manual SQL that you can write if you want to,

01:31 or I'm going to show you how to generate that with just a simple node script, so we can generate all of the insert statements that need to happen to generate all of those permissions and roles. This one's going to be pretty cool because it means that once you're done with this,

01:47 you'll understand how to seed production with some data in the database, which is a pretty common thing. Yeah, let's get started.