课程: React: Creating and Hosting a Full-Stack Site
免费学习该课程!
今天就开通帐号,24,700 门业界名师课程任您挑!
Creating a custom auth hook - React.js教程
课程: React: Creating and Hosting a Full-Stack Site
Creating a custom auth hook
- [Instructor] Alright, so as I said, the next step here is going to be to create a custom React hook that we can use to very easily learn in any of our page components or other components such as a nav bar, whether the user is logged in or not, and if they are, what their email address is, as well as other information about the user. So here's how this is going to work. Creating custom hooks in React is actually pretty straightforward. We're just going to create a new file inside our source directory called useUser.js. This doesn't even need to be jsx because it's just going to be JavaScript code. And the first thing we're going to do is import a few utilities that we're going to need from both React and Firebase Auth. So here's what that's going to look like. We'll start off by saying import { useState, useEffect } from 'react'; we're going to use both of those hooks, and then we're going to say import { getAuth, onAuthStateChanged } another rather lengthy function name there from…
内容
-
-
-
-
-
-
-
(已锁定)
Why Firebase Auth?2 分钟 9 秒
-
(已锁定)
Creating a Firebase project1 分钟 43 秒
-
(已锁定)
Adding Firebase Auth to React6 分钟 7 秒
-
(已锁定)
Build a login form8 分钟 51 秒
-
(已锁定)
Build a create account page7 分钟 23 秒
-
(已锁定)
Making interface adjustments for authenticated users6 分钟 8 秒
-
(已锁定)
Creating a custom auth hook9 分钟 3 秒
-
(已锁定)
Adding Firebase Auth to Node.js6 分钟 35 秒
-
(已锁定)
Protecting endpoints using auth tokens4 分钟 33 秒
-
(已锁定)
Protecting the upvote and comment endpoints5 分钟 7 秒
-
(已锁定)
Making requests with auth tokens7 分钟 7 秒
-
(已锁定)
-
-