#Protected Routes issue

9 messages · Page 1 of 1 (latest)

fair shell
#

hi everyone i need help in something i am making a project basically a chat app so i am trying to make a protected router using react router i am keeping track of if a user is logged in or out by using a custom hook that uses firesbase function onauthChanged it return a state islogged i export this and use this where ever i need it some place it is working fine in the component i am using for protected route it is not working it shows i am logged in but cant accees change my route this is the code on the top is custom componet then my protected route component then the Router components

scenic nebula
#

I think it’s bc you’re protecting the home path and chatpage route. Put the protected routed only around the chatpage route. I’m currently in bed rn so I’m just speculating on what I’m seeing

scenic nebula
#

did you import BrowserRouter , Routes , and Route from react router dom?

#

import { BrowserRouter , Routes , Route ,Outlet , Link , Navigate} from 'react-router-dom'

remote iron
#

I think it would be more beneficial for you to post a link to a repo or post a scrim. Based on your snippet, it looks like things are missing that may or may not actually be missing. We would be able to provide better help if all the code were available.

glad charm
#

Your use effect needs to have user in the dependency array. Also I would make the on Auth state comport an Auth provider and wrap yoir app with it. You can create a custom “use user” hook to access your user

fair shell