How It Works — MidasCloud Portal
(temporary document made with AI just for personal use so I do not forget)
This document outlines the account request → approval → access architecture for the
MidasCloud Portal.
Overview
The portal is split into three pieces:
- Front-End/ — React app, handles UI and talks to the backend via
fetch - Back-End/ — Express app (
server.js), handles all routes, auth logic, and
Discord notifications - db.js — opens/creates the SQLite database (
better-sqlite3) and exports adb
object; contains no query logic of its own
Account Request Flow
- A visitor submits a request via the frontend: username, email, and an optional
reason. - This hits
POST /api/request-accounton the backend. - The backend inserts a new row into the
userstable withstatus: "pending". - The backend fires a notification to Discord (via webhook) so the admin sees the
new request in real time.
Approval Flow
- The admin approves the request out-of-band (Discord message, admin panel — TBD).
- The approval action hits a protected endpoint (e.g.
POST /api/approve/:id),
gated behind a shared secret/admin token so only the admin can trigger it. - On approval, the backend:
- Generates a cryptographically random default password
(crypto.randomBytes, notMath.random) - Hashes it with
bcrypt.hash()— the plaintext is never stored - Updates the user’s row:
status: "approved",password: <hash>,
hasDefaultPwd: true - Sends the user their username + one-time plaintext password (Discord DM/email —
TBD)
- Generates a cryptographically random default password
Login Flow
- User submits username + password via the frontend to
POST /api/login. - Backend looks up the user by username, then runs
bcrypt.compare()against the
stored hash. - On success, the backend responds with JSON — it does not redirect
server-side:{ "success": true, "mustChangePassword": true } - React reads
mustChangePasswordfrom the response and handles navigation
client-side (e.g. via React Router), routing first-time users to a
change-password screen.
First Login / Password Change Flow
- User is prompted to set a real password.
POST /api/change-passwordhashes the new password withbcrypt.hash(),
overwrites the stored hash, and flipshasDefaultPwdback tofalse.- User now has full access to the portal.
Access / Redirect
Once authenticated with a real password, the user is directed to their vault,
served via a Cloudflare Tunnel pointed at localhost:3000.
Notes / Open Items
- Admin-approval endpoint auth mechanism (shared token vs. session-based) — TBD
- Discord webhook wiring for both the request-notification and password-delivery
steps — TBD - CORS setup between frontend and backend subdomains — not yet implemented