简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM