Hi Maksim. There is a bug in this code. After watching the video after this, I realized you fixed it before the next video, but you did not mention it anywhere in either videos. It's in Auth.js. In between the two videos (because you start that video with a recap), it appears you wrote the pending/loading logic. Without this logic, private route will hit the too early, while the check for currentUser is still pending. But thanks for the video, very helpful series!
@satansdeer14 жыл бұрын
Thanks for the comment, i've pinned it so others can also see it. Later ill update the code in the attached repo.
@nazliton53064 жыл бұрын
Can you expand further on how to fix this bug ?
@alexanderdeimos16874 жыл бұрын
@@johnparsons4434 I found a bug and try to fix it using async/await. Like await onAuthStateChanged(); setLoading(false), but that's not working. When i use example from repo - its done. Can you please explain how it works?
@nazliton53064 жыл бұрын
@@johnparsons4434 Thanks for that, fixed a bug I was working around for weeks :)
@AlanJudson3 жыл бұрын
Thanks Maksim! I have been using PrivateRoutes with this, and I've put in the pending/loading logic, but every time I click on a navigation link, it says it's loading, so there's always a little blip that looks like a page refresh (but isn't). I'm wondering if there's a work-around, or a way to only get it to reload for redirects. Anyone have any thoughts?
@StevenBoutcher2 жыл бұрын
Holy f***ing f***, man, you're a lifesaver!! I've been bouncing around the internet for months and somehow missed your video, but yours is the first one that worked for me! I just had to refactor a couple of things so they worked for React Router v6 & Google auth (Firebase). If you haven't yet, doing another video with that combo would be amazing. Thanks so much for taking the time to post this, it saved me so much frustration
@chrisc.41442 жыл бұрын
What changes did you make? As soon as I wrap my routes in an AuthProvider, everything disappears when the app runs. Idk how many different tutorials and code examples I’ve used to try and fix this but nothing is working. Ended up going with Auth0 because their AuthProvider works right out of the box
@eaglebirdiepar5 жыл бұрын
Theon you’re a good man
@CognitiveSurge5 жыл бұрын
lmao
@joshuaalphonse5215 жыл бұрын
LOL
@jesusmendoza77745 жыл бұрын
LMAO
@Miodrag02045 жыл бұрын
xD
@mf28105 жыл бұрын
oh wow, best react video comment ever
@geovanejunior31544 жыл бұрын
Theon Greyjoy is a great teacher.
@paullukic11355 жыл бұрын
Most useful tutorial I have found on the internet about firebase auth, thanks a lot for sharing.
@paulm94005 жыл бұрын
Thank you. Clear explanation with new version of React router 5.0 and react 16.8(withHooks)
@satansdeer15 жыл бұрын
Paul Miller thanks
@ChrisGWGreen3 жыл бұрын
Thanks Maksim, went down the react-firebase-auth-provider route but it felt clunky. Your solution feels a lot more lightweight. Thanks so much.
@irzoltan5 жыл бұрын
Love it! - Also, don't forget to `yarn build` after you update the `.env` file.
@rayywaii_4 жыл бұрын
Thanks man, your reply helped me
@vittoriomorellini19392 жыл бұрын
Simply explanation that explain perfectly Firebase. This service simplify the user manage
@kavinduvindikasomadasa3525 жыл бұрын
without going through all the way upto the end in video...I was able to figure out how to work with firebase auth...thank you for this great video...!
@chinmayphanasgaonkar4 жыл бұрын
i saw many tutorials but this was the best
@kallilfreire9724 жыл бұрын
Finally a good and functional tutorial! Thanks, bro
@kwadwoagyapon-ntra21764 жыл бұрын
Awesome tutorial. It undid a lot of the damage a previous tutorial did to my knowledge on this subject.
@satansdeer14 жыл бұрын
wow, glad to hear
@reydez842 жыл бұрын
damn, this helped me so much bro, better than the 1hr long ones lmaoooo
@anvarsaidov89643 жыл бұрын
Great tutorial, liked (fat like) and subscribed, keep it up bro, watching you from Uzbekistan
@wrutzreaction71994 жыл бұрын
amazing tutorial ,this is the best interms of authentication using react and firebase...this video helped me a lot
@xurify4 жыл бұрын
You're a god, how are you not more popular
@NateFreight4 жыл бұрын
Super easy to follow. Implemented it in my own project. Thanks dude
@emday4prez4 жыл бұрын
According to the update log of the firebase SDK (version 8.0.0), the way to import firebase SDK should be` import firebase from 'firebase/app' `instead of ` import * as firebase from 'firebase/app'`
@adrian_franczak4 жыл бұрын
On login page i found this error :/ "Uncaught Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops."
@igorkirey16423 жыл бұрын
Very nice! Many thanks for this tutorial. I got head-ache trying to understand everything from scratch, but using your code and vide - super great!
@modeezy23413 жыл бұрын
This is exactly what I needed for my project! Thank you!
@hypergraphjs97395 жыл бұрын
This is very useful. Thanks for the video!
@AlexCastillo-dy6db4 жыл бұрын
Thanks for the video. What is happening in your useEffect hook? At 3:30, onAuthStateChanged takes a cb as an argument, and you're passing a reference to setState. Why does this work without calling setState and passing an argument to it?
@christinaharris95282 жыл бұрын
Just found out after a barrage of errors that react-router and react-router-dom have updated. Instead of Redirect it's now Navigate. Also had to make a custom hook for withRouter to work and also had to wrap anything that uses Router with Routes. Other than that this was a quick and easy tutorial to follow. I should have checked the date lol.
@edgarsboronovskis7382 жыл бұрын
Thank you for the heads up! I thought I was losing my mind.
@TheSanchezxd4 жыл бұрын
thanks dude the solution was pretty simple it is that I was stuck maybe because of the quarentine
@TotallyNotZoid4 жыл бұрын
Thank you so much man, quick and straight to the point. Worked like a charm man!
@baileyritchie57115 жыл бұрын
What is the best way to go about private pages for users with different access points? I am trying to create an admin only portal for my site, and the setup in this tutorial simply lets anyone access if they are logged in. I am struggling to get currentUser from context, because it always appears null. Is the better way to do this through setting up the admin access values in Auth (through context) instead of in my login file?
@PriyanshuKumar-wu4wk3 жыл бұрын
I have checked many times my "Auth.js" and "PrivateRoute.js" all the things , are same as video, but still getting this error : "Cannot destructure property 'currentUser' of 'Object(...)(...)' as it is undefined." I have already applied the previous mentioned changes in Auth.js of adding "Pending state", but still the error won't go away.
@Zenyrus3 жыл бұрын
Had the same problem, check your AuthProvider did u set that up properly
@thedeveloper42075 жыл бұрын
Amazing Video....Please don't stop making videos because I have pressed the bell button too😄
@satansdeer15 жыл бұрын
Wow, thank for support!
@dmitruz19002 жыл бұрын
export 'Redirect' (imported as 'Redirect') was not found in 'react-router' (possible exports: MemoryRouter, Navigate, Outlet, Route, Router,
@RalphTonTuteur4 жыл бұрын
Very nice tutorial. But i can't seem to grasp why you use the Callback Hook... In what instance, would the handle login function be called without you wanting it to be? It seems to me it will only be called when the login form is submitted which is what we want. So I am not sure why we add this with the history dependency, it seems unecessary. Could someone explain what I am missing here ?
@paradoxalJohn Жыл бұрын
I have installed firebase, created a .env and a base file just like you did here. However, it will not recognize 'auth()' as a property of type 'FirebaseApp' (I'm using TypeScript). Can't seem to solve this.
@NairiAreg4 жыл бұрын
what is .env? I don't have one do I have to create it myself?
@stevenjchang4 жыл бұрын
yes, create it yourself, but also add it to your .gitignore file in your project root folder. env means environmental variables. It should be hidden and not pushed to github, as those are your private keys.
@NairiAreg4 жыл бұрын
@@stevenjchang thanks a lot
@Elator117773 жыл бұрын
I wish I knew about your channel when I started to learn JS, that was about the time you made this video! But at that time, I didn't know. If Had, my knowledge would be better now.
@satansdeer13 жыл бұрын
What resources did you use to learn JS as a beginner?
@Elator117773 жыл бұрын
@@satansdeer1 FreeCodeCamp CodeAcademy PluralSight Those were my favourite because you get to write code and run it right on their platforms. I also watched a couple of courses, read several articles and did a lot of katas on codewars. Im still learning but with emphasis on react and related libraries.
@antdx316 Жыл бұрын
now how do you add the others like Google? also how do you make it where each user has where they left off?
@freesoul23774 жыл бұрын
Line 7:25: React Hook "useCallback" is called in function "login" which is neither a React function component or a custom React Hook function react-hooks/rules-of-hooks Line 22:28: React Hook "useContext" is called in function "login" which is neither a React function component or a custom React Hook function react-hooks/rules-of-hooks i am facing this can you help
@DevilDude4 жыл бұрын
The component needs to have a name begining with a capital letter. It should be Login not login.
@MariusMathisenVLOG5 жыл бұрын
When "logged in" the route seems to jump to /login for 1 sec. It's seems to be becouse of PrivateRoute component where it interpets currentUser as null first, and load again to find the current user. The results is that /login flashes for 1 sec, then route to Home-component. Why is that?
@radonjamarinkovic5 жыл бұрын
It happens to me also but in other case. If user is logged in, every time i press refresh button route jumps to login page for 1 sec.
@hristoenev67335 жыл бұрын
That is because the render happens before the response is received from Firebase. Sadly this tutorial doesn't handle these cases.
@luismiguelascencio40654 жыл бұрын
I have this same issue, could someone help me out? how can I wait to trigger the render after we check the status of current user?
@zcto4144 жыл бұрын
Same problem here as well. @Maksim Ivanov, could you please help us here? Do you have any suggestions on how to solve this issue?
@Melvin420x123 жыл бұрын
I do not understand why you're using `useCallback` here and what the `withRouter()` is for... I tried the same setup with `useHistory()` to get access to the history object and just replace `useCallback` with an async function. And it acts exactly the same. Could you please explain why you choose to use `useCallback` and `withRouter`? Thanks!
@gwapster135 жыл бұрын
Great tutorial. Thanks.
4 жыл бұрын
Thanks man! Saved the day
@dmitruz19002 жыл бұрын
I have an error Uncaught TypeError: (0 , _firebase__WEBPACK_IMPORTED_MODULE_1__.useAuth) is not a function
@useyourname244 жыл бұрын
Great tutorial. I integrated this into a little side app and all seems good to go. Now I'm just curious how to handle multiple protected routes. In any case, this was an excellent guide. Subscribed.
4 жыл бұрын
At 1:45 you said, "Make sure to install firebase, react-router, and react-router-dom". Here are the instructions: In the root folder (here it is "react-firebase-auth") run the command below: npm install --save firebase npm install --save react-router npm install --save react-router-dom
@CroMatej4 жыл бұрын
Thank you
@abhishekpatel76244 жыл бұрын
Thanks man... Actually I'm stuck last two days. How to set env variables and hide firebase key in react I'm trying all the stackoverflow & documentations steps but it's not finally your video recommended by the KZbin randomly and just for the learning i click and saw whole video after video i changed into project and wolla its perfectly working 🙂✨
@cloudeater95714 жыл бұрын
The dot env is only for development and testing I presume? As the key would be exposed as part of the javascript bundle I’d imagine. Would you recommend just generating a new key once things get to production, or is there some other method you’d recommend? I have never used firebase before
@energyimpulsedel7124 Жыл бұрын
Doesn`t work PrivateRoute 2023 in must be only component
@elmehdiettalab47564 жыл бұрын
Straight to the point!! Thanks man
@mgominasian92065 жыл бұрын
why history push and also redirect the history.push is not working in the login component so it is getting rendered again but but the other check it will redirect it with the component why?
@Malcolm777-i5 жыл бұрын
When you are on the home screen and reload the page login form will show again and redirect to the homepage again.
@Shubhaw5 жыл бұрын
Yes, I am facing the same issue and it doesn't look good when there are multiple components (with different different route paths) and if you refresh, it actually reloads the login page and then redirects to the homepage! If anybody finds out how to redirect to the same path (the page which was open earlier), please share the code here.
@Malcolm777-i5 жыл бұрын
@@Shubhaw I think this is the suspect !!currentUser ? ( ) : ( ) } located at PrivateRoute.js
@Malcolm777-i5 жыл бұрын
@@Shubhaw This will help you github.com/georgeiliadis91/react-firebase-auth/blob/master/src/Auth.js credit the owner :)
@ayaanmomin83334 жыл бұрын
How can I connect auth with firestore? In the sense, how can I make or access a document inside a collection called users, and then access the user data?
@alehsiarheyeu82554 жыл бұрын
Спасибо огромное!👍 С большой радостью открыл для себя твой канал!🔥 Продолжай в том же духе!🚀
@ilug85714 жыл бұрын
I have never learn so much from a video, and AWESOMEEE minecraft stickers 🚀💯
@chris789454 жыл бұрын
Excellent tutorial! If you ever decide to do a remake, I'll love to see how to manage idToken and timeout in the authentication process.
@andreikudriavtsev74024 жыл бұрын
Why you use useCallback in onSubmit event? I don't see any React.memo exports in your code
@jeremyi4 жыл бұрын
I can't seem to solve this error: Error: Invariant failed: You should not use outside a The withRouterLogin IS called inside a I tried with your code from Github and got the same result. Thank you for your help!
@MohiyuddinShaikh4 жыл бұрын
Great video but a question, can we not use history like this : import { useHistory } from 'react-router-dom'; and then in the function say : function Home(){ let history=useHistory(); if(signUpSuccessful){ history.push("/home") } }
@satansdeer14 жыл бұрын
Mohiyuddin Shaikh you mean just use the browser history object instead of the hook?
@MohiyuddinShaikh4 жыл бұрын
@@satansdeer1 Yes.
@satansdeer14 жыл бұрын
Mohiyuddin Shaikh it will work, but there might be some slight differences in how history api works in different browsers and by using the react-router wrapper of it. Here's a documentation on react router history object: github.com/ReactTraining/history#properties
@MohiyuddinShaikh4 жыл бұрын
@@satansdeer1 Great, Thanks Man !
@hussainsalih35202 жыл бұрын
great tutorial keep moving :)
@shamilmammadov82465 жыл бұрын
Спасибо за столь наглядный пример. Очень хотелось бы увидеть реализацию данного подхода с Redux.
@satansdeer15 жыл бұрын
Shamil Mammadov при авторизации через firebase redux не особо нужен. Возможно запишу видос, как работать с firestore + redux
@marcosraul41324 жыл бұрын
Awesome tutorial, one thing though, u definitely should not use "useCallback" for a simple "handleClick", that is used for parent components that have many many childs and a re-render is really costly. Adding that without measuring the impact of not having it does more harm than good.
@bensonluis98464 жыл бұрын
Hi, my /login and /signup does not show anything. It's just white. When I try to re enter the path, it shows the h1 and inputs briefly then become white screen again. Pls heeeelp thanks
@taqikhan54183 жыл бұрын
where did you get the code of .env file from?
@plastikkman4 жыл бұрын
Hi there, wouldn't it be a security risk storing the firebase key in your code?
@plastikkman4 жыл бұрын
If someone was able to overcome this limitation please let me know how! 😄
@mdyamin0073 жыл бұрын
Simple and easy explanations among all the videos. Thanks a lot ♥
@deepL0 Жыл бұрын
1:36 Hahaha I laughed a lot for you waiting for no reason with a serious facial expression
@mudiartatauda87185 жыл бұрын
It's useful, but why my app still open login before secure route.
@satansdeer15 жыл бұрын
Mudiarta Tauda i will address this issue in one of the next vids. For now you can introduce loading state before you show the screens of your app
@miluskagonzalez40165 жыл бұрын
@@satansdeer1 hey, did you get to upload a vid addressing this issue?
@satansdeer15 жыл бұрын
Miluska González not yet, to be clear im talking about storing logged in state between page reloads. So that when you reload page and go to secure route it doesnt blink with login page. Is that the thing, or did I misunderstand what we are talking about here?
@miluskagonzalez40165 жыл бұрын
@@satansdeer1 yes, that is exactly it. Since the state starts as null and the auth is async, it takes a while to change
@EdWeng5 жыл бұрын
@@satansdeer1 Does Firebase Auth not do this automatically? What's the best way to resolve? Is it to use LocalStorage?
@ЯковГущин-г2ю5 жыл бұрын
So capaciously and understandably! Thanks
@satansdeer15 жыл бұрын
Яков Гущин спасибо)
@davidsnyder5184 жыл бұрын
how do I store the authentication in local storage so the login status persists after logout?
@alexanderpunkovsky4374 жыл бұрын
The best tutorial!
@mariomarasovic63424 жыл бұрын
Error: There is no user record corresponding to this identifier. The user may have been deleted. I can't figure out this error please help
@adammo66613 жыл бұрын
Great tutorial. However I wonder if there is an easy way to redirect user to his dashboard ('/') when he's logged in without showing login screen for split second? I implemented it and when logged user enters localhost:3000/login in address bar it shows him login page for like 0.5s and then redirects to '/'. How can I bypass showing that login page?
@jokovBG2 жыл бұрын
Hahahaha I subscribed because of the loading... moment :D
@wjrobinson113 жыл бұрын
What if you do have a back end api and want to authenticate requests to it? Would Firebase no longer be a viable solution?
@LegendarySkyHero4 жыл бұрын
What about authentication with Google, Apple, Github?
@Dev_Everything3 жыл бұрын
Can you PLEASE do a react, node, passport local with a mysql or just in memory array?
@ВадимРошко5 жыл бұрын
Why we using withRouter if our Login and SignUp pages are already in and have access to history?
@apayrus4 жыл бұрын
Спасибо, Максим, очень интересно объясняешь. И материал урока подготовил хорошо. 👍
@asharashfaque5 жыл бұрын
This is just what i needed. Thanks.
@mf28105 жыл бұрын
Very clear, great tutorial - thank you - please keep making more :)
@satansdeer15 жыл бұрын
Thanks Mark
@nilmendes77105 жыл бұрын
Excellent tutorial. Good work!
@satansdeer15 жыл бұрын
Thanks Nil
@MarsTheProgrammer5 жыл бұрын
It's not working at all. Firebase has a new way of doing it too, called Load Firebase SDKs from reserved URLs. Both this old method and the new one is giving me errors... I hate that firebase completely changes things every few months.
@satansdeer15 жыл бұрын
Mars Castillon could you send an example repo, id like to check out what is broken there
@yeinnarayana26445 жыл бұрын
@@satansdeer1 hey you such a pretty nice guy, i hope you will be nice like this even if you touch more K number of subscribers. +1 from me :D
@AlanJudson3 жыл бұрын
Thank you so much, Maksim.
@TheWizardOfTech3 жыл бұрын
where can i find the .env file
@MaryoOo05 жыл бұрын
Do you have an example when the authentication is done via facebook or github? The flow is different on pop-up login flow
@satansdeer15 жыл бұрын
MaryoOo0 no but i dont think there will be any difference
@simonkalu5 жыл бұрын
Interesting tutorial. Thanks, buddy. But I am stuck with firestore authorization. Do a tutorial on how to load the sidebar menu from the firestore based on user role. This is very important
@shehzadmalik79264 жыл бұрын
really great lecture... i love it...thank u sir
@danielgreenfield89704 жыл бұрын
Extremely useful tutorial, thank you! How could I access the currentUser uid in the child components? Is there a way to pass currentUser into the PrivateRoute props? Or maybe a better way to get currentUser.uid?
@r-i-ch4 жыл бұрын
Thank you for Excellent tutorial. I am wondering if you would be able to do a TypeScript version of this? I have tried but I get many ts errors and am unable to figure out how to make it work.
@satansdeer14 жыл бұрын
Great suggestion!
@danieldbird5 жыл бұрын
How do i check for currentUser on other pages to do conditionals for displaying menu items?
@ianaustria88684 жыл бұрын
i think you can use the useContext hook to access the currentUser
@danieldbird4 жыл бұрын
@@ianaustria8868 Thanks a lot!
@yendrembamrabinchandra4764 жыл бұрын
I've installed firebase version 7.19.1. When I use auth feature, there are lot of token requests sent. Please tell me how to fix this.
@tattah964 жыл бұрын
Hi Maksim, how do I dynamically render the user data from firebase clientside? So if a user logs in, how do I render that users profile with his name etc
@gubmx204 жыл бұрын
Hi @fattah do you can use the UUID from the user and create a document in firestore relating the UUID with this document.
@RogerioOrioli5 жыл бұрын
perfect and using hooks , congrats
@oojiitech324 жыл бұрын
Hi Maksim! Is there a way to do role specific private routes using custom claims?
@satansdeer14 жыл бұрын
sure, youll just need a more complicated context provider that will check against the role instead of the simple boolean check
@atmospheric_b5 жыл бұрын
that login route flashing on every public route is not good. I already broke my brain to figure out how to do it more elegant. Like showing loading spinner but the problem is that users can stuck on that spinner component forever if they are not been logged in.
@marcincz48595 жыл бұрын
It works fine on react-create-app, but when I try to do it on webpack project I can't auth (form fields are being appended to the URL and I can't do POST request to firebase). Could you tell me how to configure webpack to work with firebase?
@satansdeer15 жыл бұрын
Marcin Cz shouldnt be that different, could you send a repo?
@marcincz48595 жыл бұрын
@@satansdeer1 github.com/MarcinCzanasz/test
@satansdeer15 жыл бұрын
@@marcincz4859 change your .babelrc to this `{ "presets": [ [ "@babel/preset-env", { "targets": { "node": "10" } } ], "@babel/preset-react" ] } `
@satansdeer15 жыл бұрын
there was a problem with async functions support
@sndhigh5 жыл бұрын
Maksim, this is a great tutorial but I am having an issue all of a sudden. i"m getting "TypeError: Cannot read property 'currentUser' of null" from PrivateRoute.jsx:6. I'm banging my head against the wall trying to figure it out. Any suggestions or insights?
@satansdeer15 жыл бұрын
Maybe the context is missing, did you wrap your whole app into AuthProvider?
@hincha0134 жыл бұрын
Thank you bro, amazing tuto !
@sidhant16085 жыл бұрын
Hello, I am trying to handle multiple protected routes but the Login component keeps redirecting me to the root component. Please help on how to do this
@satansdeer15 жыл бұрын
Sidhant Jain you need to store the redirect route then. For example when you are first redirected to private route you could append redirect-to query param to url
@sidhant16085 жыл бұрын
@@satansdeer1 Hey, I tried doing that. But since the Login component is a stateless function I am having trouble realising on how to get it in the code. Since we are already using history as props in the login component, can I still get another value as a prop ? Could you please help me out
@satansdeer15 жыл бұрын
Sidhant Jain take 'location.search' and get the query params from it you can use URLSearchParams to parse it