fix: Replace in-memory auth with bcrypt, SQLite persistence, and JWT.#947
Open
Mayur-e wants to merge 1 commit into
Open
fix: Replace in-memory auth with bcrypt, SQLite persistence, and JWT.#947Mayur-e wants to merge 1 commit into
Mayur-e wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
Closes #914
Summary
The auth system was storing passwords as plaintext in a runtime object (
const users = {}), which meant all accounts were lost on every restart and passwords were never hashed. This PR migrates auth to the existing SQLite database using bcrypt for password hashing and JWT for login tokens.Also fixes a
SyntaxErrorcaused by a duplicateconst calendarDownloadBtndeclaration inapp.jsthat was preventing the frontend from loading.Changes Made
database.js— Addeduserstable withid,email,password_hash,created_atserver.js— Removedconst users = {}; passwords hashed withbcrypt(10 rounds) on signup; login verified withbcrypt.compare(); successful login returns a signed JWT (7d expiry); startup warning added ifJWT_SECRETis missing.env.example— AddedJWT_SECRETwith a note on how to generate onepackage.json/package-lock.json— Added missingbcryptandjsonwebtokendependenciesjs/app.js— Removed duplicateconst calendarDownloadBtnat line 89 that caused a module-levelSyntaxError, crashing all frontend JSTesting
Tested locally with
node server.jsagainsthttp://localhost:3000.1. Signup returns 201 and account is created
2. Password stored as bcrypt hash in SQLite — not plaintext
3. Login returns a signed JWT token
4. Account survives server restart — login works after
node server.jsis stopped and restartedScreenshots
See Testing section above.
Checklist