golovingreg
golovingreg

Reputation: 13

How do I tell a webpage if a user is logged in?

I am building a simple blog for practice, it's just several html pages. I decided to include React to the website to get rid of repetition (I have the same navbar on all the pages). React is not installed with npm, it's just included as a module.


<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
<script src="navbar.js"></script>

Now I want to make sign in/sign up forms and want some navbar buttons change (from sign in to sign out and from register to profile) if the user is logged in.

I thought of adding a react component into the navbar.js, or creating a separate component like signin.js with react and put it into a separate signin.html page, but in this case I couldn't pass the "isLoggedIn" state to the navbar. The question is are there ways to do it just using simple HTML and react.js (as I don't really know other front-end libraries or languages).

Thanks for your help

Upvotes: 1

Views: 59

Answers (1)

Borislav Stefanov
Borislav Stefanov

Reputation: 731

I would suggest you to use sessionStorage or localStorage. There you can set parameters when user is logged. For example token or even ordinary true/false variable.

Upvotes: 1

Related Questions