Prompt file imported from yutthananpipan/DHLCarParkCoupon (
.github/prompts/plan-persistentLoginAndBackend.prompt.md). Copyright stays with the author.
me## Plan: Persistent Login & Backend API Integration
The goal is to implement persistent login using localStorage so users remain logged in after refreshing, and to set up a Node.js/Express backend that runs concurrently with the frontend to handle future printer API requests.
Steps
- Add Dependencies: Install
express,cors, andconcurrently(dev) to support the backend and running tasks in parallel. - Create Backend Server: Create
server/index.js(new file) with a basic Express app, CORS configuration, and a placeholder/api/statusendpoint to simulate the future printer connection. - Configure Scripts: Update
package.jsonto add aserverscript and modify thedevscript to run both frontend and backend usingconcurrently. - Implement Persistence: Modify
src/App.tsxAppcomponent to:- Check
localStorageon initialization to restoreemployeeIdand setcurrentScreen. - Save state to
localStorageinhandleLogin. - Clear
localStorageinhandleLogout.
- Check
- Connect Frontend to API: Create a helper in
src/constants/index.tsxor a new utility file to fetch data from the new local API, proving the connection works.
Further Considerations
- Deployment: The current
Dockerfileonly serves the frontend via Nginx. For the final production version to include the API, the Docker setup will eventually need to be changed to either run Node.js or usedocker-composeto run two containers (frontend & backend). This plan focuses on the development environment first. - Security: Does the login need real password validation later? Currently, it only checks for an ID.
- Printer API: I will structure the backend to easily accept the printer logic later.