Skip to content

feat: email/password auth + QR-based developer profile sharing (#Dev-…#537

Closed
amritbej wants to merge 4 commits into
Dev-Card:mainfrom
amritbej:feat/email-auth-qr-profile-sharing
Closed

feat: email/password auth + QR-based developer profile sharing (#Dev-…#537
amritbej wants to merge 4 commits into
Dev-Card:mainfrom
amritbej:feat/email-auth-qr-profile-sharing

Conversation

@amritbej

Copy link
Copy Markdown
Contributor

Summary

Implements email/password authentication and dynamic QR-based developer profile sharing for the DevCard platform. Users can sign up, log in, manage their social profile links from a dashboard, and share all their developer profiles through a single generated QR code that points to a public profile page.

Closes #117


Type of Change

  • Bug fix
  • New feature
  • Refactor (no functional change)
  • UI / Design change
  • Tests only
  • Documentation
  • Infrastructure / DevOps
  • Security

What Changed

Backend

  • apps/backend/prisma/schema.prisma — added nullable password_hash field to User model
  • apps/backend/prisma/migrations/20260611120000_password_auth/migration.sql — migration to add the column
  • apps/backend/src/utils/password.ts — scrypt-based hash/verify using Node.js built-in crypto (zero new deps)
  • apps/backend/src/routes/auth.tsPOST /auth/signup and POST /auth/login with zod schema validation; signup atomically creates User + default Card in one Prisma transaction
  • apps/backend/src/utils/validators.tssignupSchema and loginSchema (email lowercased, username regex, password min 8 chars)
  • apps/backend/src/services/profileService.ts — strips passwordHash from all profile API responses
  • apps/backend/src/__tests__/auth.test.ts — 4 unit tests: signup, login, duplicate email → 409, wrong password → 401

Frontend (SvelteKit)

  • apps/web/vite.config.ts — Vite dev proxy: /auth and /api forwarded to backend, eliminating all CORS issues in development
  • apps/web/src/lib/apiClient.ts — browser uses relative URLs (through proxy); extracts details.fieldErrors from zod error responses so users see e.g. "password: must be at least 8 characters" not "Validation failed"
  • apps/web/src/lib/auth.tssignup(), login(), logout() helpers, localStorage JWT store
  • apps/web/src/routes/signup/+page.svelte — signup form with real-time username hint (blur), password strength bar (Weak/Fair/Strong), red/green field borders, loading spinner, formValid guard decoupled from loading state
  • apps/web/src/routes/login/+page.svelte — login form with friendly error message, loading spinner
  • apps/web/src/routes/dashboard/+page.svelte — JWT-authenticated profile editor: display name, username, bio, role, company, accent colour; add/edit/delete platform links (GitHub, LinkedIn, Twitter/X, etc.); live QR code <img> preview; one-click copy of public URL
  • apps/web/src/routes/+page.svelte — added Log in / Create card links to landing nav
  • apps/web/src/routes/u/[username]/+page.svelte — display name now pure white (#ffffff) with accent-colour text-shadow glow; @username handle shown below name; role badge and bio text lifted to proper contrast

How to Test

  1. Start Docker: docker start devcard-postgres devcard-redis
  2. Apply migration: cd apps/backend && DATABASE_URL="..." npx prisma migrate deploy
  3. Start backend: pnpm --filter @devcard/backend dev → runs on http://localhost:3000
  4. Start frontend: pnpm --filter @devcard/web dev → runs on http://localhost:5173
  5. Go to http://localhost:5173/signup → create an account (username: letters/numbers/_/- only, password: min 8 chars)
  6. You are redirected to /dashboard → add GitHub, LinkedIn, Twitter links; set bio and accent colour
  7. Click Copy Link or scan the QR code → opens /u/<username> public profile showing all links
  8. Log out, go to /login, log back in → redirected to dashboard
  9. Run backend tests: pnpm --filter @devcard/backend test → 4/4 pass
  10. Run type check: pnpm --filter @devcard/web check → 0 errors

Checklist

  • My code follows the project's coding style (pnpm -r run lint passes).
  • TypeScript compiles without errors (pnpm --filter @devcard/web check → 0 errors).
  • I have added or updated tests for the changes I made (4 new backend auth unit tests).
  • All tests pass locally (pnpm --filter @devcard/backend test → 4/4 pass).
  • I have updated documentation where necessary.
  • No new console.log or debug statements left in the code.
  • Breaking changes are documented in this PR description. (No breaking changes — password_hash is nullable so existing OAuth users are unaffected.)

Screenshots / Recordings

Devcard Login Develper_profile devcard-dashboard

Additional Context

  • Zero new backend dependencies — password hashing uses Node.js built-in crypto.scrypt
  • Backward compatiblepassword_hash column is nullable; existing GitHub/Google OAuth users have null and are unaffected
  • Vite proxy is dev-only — in production the frontend and backend should be served behind the same reverse proxy (or PUBLIC_API_URL env var should be set)
  • JWT stored in localStorage — a future improvement would be to move to httpOnly cookies for better XSS protection

…Card)

## Summary
Implements full user authentication and dynamic QR-based developer profile
sharing for the DevCard platform.

## What's new

### Backend
- **Password auth** — `POST /auth/signup` and `POST /auth/login` using
  Node.js built-in `crypto.scrypt` (zero new dependencies)
- **Zod validation** — email normalised to lowercase, username regex
  `[A-Za-z0-9_-]{3,50}`, password min 8 chars
- **Atomic signup** — user + default Card created in a single Prisma
  transaction; existing OAuth users unaffected (nullable `password_hash`)
- **Security** — `passwordHash` stripped from every API response
- **Migration** — `20260611120000_password_auth` adds nullable
  `password_hash` column
- **Unit tests** — 4 tests: signup, login, duplicate-email 409,
  wrong-password 401 (all pass)

### Frontend (SvelteKit)
- **`/signup`** — real-time username format hint, password strength bar
  (Weak/Fair/Strong), red/green field borders, spinner on submit
- **`/login`** — friendly 'Email or password is incorrect' message
- **`/dashboard`** — JWT-authenticated page: edit display name, username,
  bio, role, company, accent colour; add/edit/delete platform links (GitHub,
  LinkedIn, Twitter/X, etc.); live QR code preview; one-click copy URL
- **Landing page** — Log in / Create card CTAs in nav
- **Public profile** (`/u/:username`) — display name now pure white with
  accent-colour glow, @username handle shown, role badge and bio lifted
- **Vite dev proxy** — `/auth` and `/api` forwarded to backend; browser
  uses relative URLs so no CORS issues
- **Bug fix** — `devcard/[id]/+page.server.ts`: catch variable was shadowing
  the imported SvelteKit `error` helper
- **Bug fix** — Svelte 5 reactivity: `$derived` for profile/error props
- **Bug fix** — `apiClient.ts` extracts `details.fieldErrors` from zod
  responses so users see exact field messages instead of 'Validation failed'
- **Bug fix** — signup submit was immediately returning because `canSubmit`
  included `!loading`; fixed by separating `formValid` from loading state

## Test plan
- All 4 backend auth unit tests pass (`pnpm --filter @devcard/backend test`)
- `svelte-check` — 0 errors
- Manual E2E: signup → login → add links → public profile → QR code all work

Closes: email-auth, profile-management, QR-sharing
@vercel

vercel Bot commented Jun 11, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Prashantkumar Khatri's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown

Hi @amritbej,

Thanks for opening this pull request.

This PR has been automatically classified based on the files modified.

Applied Labels

  • backend
  • web

Primary Review Area

  • backend

Reviewer

@Harxhit has been identified as the primary reviewer for this pull request.

If you have any questions regarding the affected area or implementation details, feel free to reach out to the assigned reviewer.

Thank you for your contribution!

@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown

CI — Checks Failed

Backend — FAIL

Check Result
Lint FAIL
Test PASS
Typecheck PASS

Mobile — SKIP

Check Result
Lint -
Test -

Web — FAIL

Check Result
Check FAIL
Build PASS

Last updated: Thu, 11 Jun 2026 17:37:07 GMT

Amrit added 3 commits June 11, 2026 23:04
…profile-sharing

# Conflicts:
#	apps/backend/src/routes/auth.ts
#	apps/web/src/lib/apiClient.ts
#	apps/web/src/routes/+page.svelte
#	apps/web/src/routes/devcard/[id]/+page.server.ts
#	apps/web/src/routes/u/[username]/+page.svelte
#	apps/web/vite.config.ts
@amritbej

Copy link
Copy Markdown
Contributor Author

@Harxhit , please review the pr

@Harxhit Harxhit added the gssoc:approved Required label for every approved PR. Gives the base +50 points and enables contribution tracking. label Jun 11, 2026
@ShantKhatri

Copy link
Copy Markdown
Collaborator

These changes are not supposed to be for web. Closing this PR.

@amritbej

Copy link
Copy Markdown
Contributor Author

@ShantKhatri ,
The PR was closed because web changes weren't supposed to be in Svelte. Should I resubmit with the frontend rewritten in React, or is a backend-only PR acceptable for now

@amritbej amritbej deleted the feat/email-auth-qr-profile-sharing branch June 12, 2026 06:25
@amritbej amritbej restored the feat/email-auth-qr-profile-sharing branch June 12, 2026 06:26
@amritbej amritbej deleted the feat/email-auth-qr-profile-sharing branch June 12, 2026 06:28
@amritbej

Copy link
Copy Markdown
Contributor Author

@ShantKhatri ,

Should I resubmit as a backend-only PR (auth routes, password hashing, migration, tests with no frontend code)? or should frontend work be tackled—separate PR or different tech stack? what to do ??

@ShantKhatri

Copy link
Copy Markdown
Collaborator

@ShantKhatri ,

Should I resubmit as a backend-only PR (auth routes, password hashing, migration, tests with no frontend code)? or should frontend work be tackled—separate PR or different tech stack? what to do ??

Just BE changes with approval from @Harxhit . As we are expecting any feature of related to this issue in web.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend gssoc:approved Required label for every approved PR. Gives the base +50 points and enables contribution tracking. web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add User Authentication and QR-Based Developer Profile Sharing

3 participants