课程: React: Authentication

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Implementing JWTs on the front end

Implementing JWTs on the front end - React.js教程

课程: React: Authentication

Implementing JWTs on the front end

- [Instructor] Okay. So we've created two routes on our backend now for allowing users to create an account and log in with the credentials that they've specified. So now that we have that logic available to us on the backend, it's time to add logic on the front end to integrate JWTs. Now, one way that we could do this would be to simply add that logic directly to our login page and sign up page. But one are the nice things that React allows us to do via hooks is define this logic once, and then simply import it into both our signup and login pages and use it there. You'll see what I mean in just a minute. So the basic idea of what we're going to do here is this. When a user clicks signup, or login, on our respective pages that we have here, both those pages are going to make a request to the corresponding route on the backend, which as we've seen will return a JSON web token containing the user's data. And then what…

内容