Applied Require Admin to Components
Welcome back to the course. In this video I'm going to show you how we can use this require admin component throughout our application.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

First thing we want to do is take this import and we want to go to newsletterLatest.js and pasted in here. Now let's wrap this button with the component, so let's take it and let's wrap it, require admin. Okay so we've wrapped the button now with require admin so we should be good to go. Let's go try it out and make sure that we can't edit newsletterLatest components.

Okay log in, it's gone. All right, now that's good, we should be good there, we can't add we can't remove. Let's go sign in again all right, so let's go and let's type in John Cena and you'll see we have access to these buttons now.

large

Sweet, so that's good. Let's see what else we have to remove, so we've got to get rid of these move buttons, we don't want to be able to move these if you're not an admin, you only want to be able to look at them.

large

So let's go to requestsItem.js and let's import it. So say import RequireAdmin from '../auth/requireAdmin';, okay we are good there. Now what we need to do is we just need to wrap this button now, we need to wrap this button move with it, so let's say require admin and lets take this button and throw it in here.

requestsItem.js

<RequireAdmin>
    <Button className='requests-item__move' icon={moveButtonIcon} callback={() => this.handleStatus()}/>
</RequireAdmin>

Login and you'll see that now we can't move these. Sweet, so that's good, we only want to view them. Now we need to get rid of this plus button, we only want admins to add new requests. So let's go into, first let's snatch this import RequireAdmin, and let's go into requestsGrid.js let's import it and let's wrap this button with it.

Okay so pretty much all buttons as we've been seeing although there's going to be a few that aren't buttons that are a little more involved. So what we want to do is check this out, let's login and you'll see we don't have access to that because we're not an admin.

So there's one more thing we need to do, we need to make it so users will only see their requests. Now we haven't created any request so we can't really see this. So let's talk about that in the next video.

Terminal

git status
git add .
git commit -m "require admin component on multiple functions"
git push origin master

And I'll see you in the next video.

Resources

Source code