wgwz / simple-cookie-express-react-app

Minimal react app that interacts with an express server to illustrate a user session

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple cookie express/react app

This code is a study of a minimal react app, which interacts with an express backend to conceptually illustrate a cookie-based user session. It is based off this video and corresponding gist (thanks Amasaabu!).

How it works?

The express app exposes two endpoints that do the following:

  1. POST to / with url query params: ?name=foo.
  2. GET to / returns the name of the active session.

The react app presents a form that accepts a username, and it also has a button that will retrieve the active name in the user session. This more or less demonstrates how an authentication takes place.

How to run it?

  1. cd backend && npm run dev
  2. cd frontend && PORT=3001 npm run start

Server-side vs client-side considerations

By using express-session this example commits to using server-side sessions. An alternative would be to actually store the user session data in a cookie is to use cookie-session.

Disclaimer

Be careful with cookies and users data.

About

Minimal react app that interacts with an express server to illustrate a user session

License:MIT License


Languages

Language:TypeScript 40.8%Language:HTML 28.1%Language:JavaScript 15.9%Language:CSS 15.2%