I am new to firebase authentication, and I can't find any info about this feature that I want to implement:
- A user types this in a search bar:
mywebsite.com/admin
- If the user is logged in
-->
send him/admin
page - If the user is not logged in
-->
send him different page
Can I implement this on the server-side? Or I still need first to load one page (/admin
), and only then redirect the user to different page?
I use next.js + express + AWS hosting + React
, in case in may be useful.
On the server-side in the code for your admin page you will need to get the ID token of the user to detect if they're logged in, and authorized, to access the page. If not, you'll redirect them back to the main page.
This process is best described in the Firebase documentation on verifying ID tokens, but boils down to: