From the course: React: Creating and Hosting a Full-Stack Site
Unlock this course with a free trial
Join today to access over 24,700 courses taught by industry experts.
Creating a custom auth hook - React.js Tutorial
From the course: 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…
Contents
-
-
-
-
-
-
-
(Locked)
Why Firebase Auth?2m 9s
-
(Locked)
Creating a Firebase project1m 43s
-
(Locked)
Adding Firebase Auth to React6m 7s
-
(Locked)
Build a login form8m 51s
-
(Locked)
Build a create account page7m 23s
-
(Locked)
Making interface adjustments for authenticated users6m 8s
-
(Locked)
Creating a custom auth hook9m 3s
-
(Locked)
Adding Firebase Auth to Node.js6m 35s
-
(Locked)
Protecting endpoints using auth tokens4m 33s
-
(Locked)
Protecting the upvote and comment endpoints5m 7s
-
(Locked)
Making requests with auth tokens7m 7s
-
(Locked)
-
-