Next.js Discord

Discord Forum

Firebase Authentication best practice

Unanswered
Atlantic herring posted this in #help-forum
Open in Discord
Atlantic herringOP
I've implemented Firebase Authentication in this Next.js project following Google's/Firebase's documentation. It works perfectly—I can sign in, retrieve data, and get redirected to the next page as expected.

However, I’m currently facing an issue: the initial dashboard page (/dashboard) can be accessed without being authenticated/signed in. This page should only be accessible when a user is properly signed in with a valid account.

What’s the best way to implement this?
What are the best practices?

3 Replies

You can conditionally render.
Just by a boolean variable suppose isLoggedIn then check if isLoggedIn ? <Dashboard/> : <Login/>