Secure a Next.js App with a Login Screen

Vladimir Novick
InstructorVladimir Novick
Share this video with your friends

Social Share Links

Send Tweet
Published 3 years ago
Updated 3 years ago

In this video lesson, we will build ProtectedPage component, which will let us secure our Video Processing page behind the Login screen. The reason for doing so is because in order to process the video, we will need an access token from Symbl.

Vladimir Novick: [0:01] Let's create a protected page component to secure our page with the login screen. We'll import React. We'll import a bunch of components from @chakra-ui/react. We'll import the header that's already created.

[0:18] Now, let's create the protected page component. We'll pass children, and we'll define a simple variable is logged in. We'll check whether if user is logged in. If it's not logged in, then we'll render some sort of a loginScreen. Otherwise, we'll render children.

[0:37] Wrap our loginScreen with the sacral couple of inputs. One input will have an AppID. It will be an AppID. The other one will be appSecret. Now, let's switch to our index.js, and wrap our page for the protectedPage component. Instead of using React fragment here, we'll remove the header, and we'll pull the protectedPage.

[1:09] We forgot to add children here, as a second class. As you can see, we have an AppID and appSecret. Let's add the button to do an actual login if you click on it. Let's define our AppID in our state as well as our appSecret.

[1:35] What we are doing here, we're creating connected components for both of our input fields. We'll bring useState from React, and we'll assign onChange handler to our AppID and AppSecret. Let's setApp a value into the AppID. Here, the value will be appSecret. Let's see if that is working. As you can see AppID and appSecret are updated.

egghead
egghead
~ 8 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today