How to redirect users back to auth page if email is not verified? #240
-
Firstly, thanks for making next-firebase-auth. Its making authentication for my web app way easier. I want to redirect users back to the auth page if they aren't logged in or if their email isn't verified. I only want users with verified emails to be able to use the web app at all. All others should be redirected to the auth page. I know I can use AuthActions to redirect users that aren't logged on, but how can I redirect users who don't have verified emails? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
I solved it, and its a lot easier than I thought it would be. To redirect users who haven't logged in, I just use AuthActions and withAuthUser, as described by the documentation. To redirect users who have logged in or signed up, but don't have a verified email, I've put in this block of code:
It's not wrapped in a useEffect or anything, it's just inside the function component. I return the Loading component because router.push takes a little time, and the page will render if you don't return anything. This works fine, but it would be really cool to be able to do this by just using next-firebase-auth. Maybe we could be allowed to customize when |
Beta Was this translation helpful? Give feedback.
I solved it, and its a lot easier than I thought it would be.
To redirect users who haven't logged in, I just use AuthActions and withAuthUser, as described by the documentation.
To redirect users who have logged in or signed up, but don't have a verified email, I've put in this block of code:
It's not wrapped in a useEffect or anything, it's just inside the function component. I return the Loading component because router.push takes a little time, and the page will render if you don't return anything.
This works fine, but it would be really cool to be able to do this by just using nex…