Secure Login V2#16
Open
SynthicProgram wants to merge 9 commits into
Open
Conversation
main replaced config/reset.js with db/schema.sql + db/seedData.js + db/resetDatabase.js and renamed every users column (id -> user_id, password -> password_hash, points -> total_points, favorite_team moved out to the followed_teams table). This branch's GitHub OAuth work was built on the old names, so the merge needed more than a textual resolve. Schema (db/schema.sql is now the single source of truth): - password_hash is nullable — an OAuth account has no password of ours - added github_id and access_token; reused main's profile_image_url for the GitHub avatar instead of adding a second column - users_has_credential CHECK enforces password_hash OR github_id Code: - auth.js: githubid/avatarurl/accesstoken -> github_id/profile_image_url/ access_token; linking a GitHub account to an existing local one no longer overwrites that user's chosen username - usersController.js: main's column names + this branch's bcrypt compare; PUBLIC_COLUMNS keeps password_hash and access_token out of responses - server.js: kept the passport/session/cors setup, updated deserializeUser to the new columns, session secret now reads SESSION_SECRET - resetDatabase.js: bcrypt-hashes demo passwords instead of seeding plaintext, so `npm run reset` produces logins the API can verify - .env.example: documented the GitHub OAuth / session vars Verified: schema.sql applies cleanly against Postgres, the CHECK accepts an OAuth-only row and rejects a credential-less one, and a seeded hash round-trips through bcrypt.compare (all in a rolled-back transaction). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The merged schema made users.username NOT NULL UNIQUE, but the OAuth verify callback wrote the GitHub login into that column unconditionally. Any GitHub login matching a username already taken by a local signup raised a unique violation and 500'd the callback
Add a /signup page wired to POST /api/users, which previously had no UI.
…ate a session cookie/secret in .env before bootup
ShalomDee
added a commit
that referenced
this pull request
Jul 27, 2026
Frontend: core pages, Fixture Calendar, Team Follow, Profile Customization (excludes login, deferred to #16)
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.
Auth: GitHub OAuth + password signup, hardened sessions
The old login compared passwords in plaintext and had dead Google/Apple buttons.
This replaces it with real auth: local email/password signup and GitHub OAuth,
both ending in the same server side session.
Server
GitHub OAuth at
/auth/github, using passport-github2.Sessions via express-session + passport.
httpOnly,sameSite=lax,securein production.password_hashnever reaches the store.Passwords via bcrypt.
bcrypt.compareon login.are registered.
a clean 409 on duplicates.
Other
CLIENT_URL.config/urls.js.browser.
PGSSL=falseescape hatch for a local Postgres that does not speak SSL.Client
/signuppage with validation matching the server.and shows a readable message for
?error=codes from the callback.Homerevalidates the server session instead of trustinglocalStorage. Theold check rendered the page as signed in when no live session existed.
Schema (breaking, requires a DB reset)
users.password_hashis now nullable.users.github_id VARCHAR(255) UNIQUEadded.users_has_credentialCHECK enforces at least one of the two.resetDatabase.jshashes on insert.Before running
Code/server/.env.exampleto.env.SESSION_SECRET. The server refuses to start without it.GITHUB_CLIENT_IDandGITHUB_CLIENT_SECRET. The callback URL registeredon the GitHub app must be exactly
${SERVER_URL}/auth/github/callback.resetDatabase.js.Note for reviewers
createUserand the OAuth verify callback both check then insert, so they lean onthe unique constraint as the real guarantee under concurrency. Both catch 23505 and
turn it into a clean 409 or
account_conflict. Worth a second pair of eyes.