- React
- React Hooks
- useState
- useEffect
- useContext
- Context API
- Local Storage
- Vite
Live demo: https://react-authentication-app.vercel.app
A small demo of sharing login state across components with React Context.
Logging in with any valid-looking email and a password of at least 9
characters stores the email and a random placeholder token in localStorage;
logging out clears them. The password field has a Show/Hide toggle.
This is not real authentication. There is no backend: the "token" is a random string generated in the browser and the "secret" page is shipped in the JavaScript bundle to everyone. Use it to learn the Context API pattern, not to protect anything. Real apps should verify credentials on a server and keep session tokens out of
localStorage(e.g. inHttpOnlycookies).
Requires Node.js 20.19+ or 22.12+ (verified with Node 24).
npm install
npm run dev| Command | Description |
|---|---|
npm run dev |
Start the Vite dev server |
npm run build |
Production build into dist/ |
npm run preview |
Serve the production build locally |
npm test |
Run the Vitest test suite |