Skip to content

Fix/username redirects#638

Open
Nareshkumawat-star wants to merge 2 commits into
Dev-Card:mainfrom
Nareshkumawat-star:fix/username-redirects
Open

Fix/username redirects#638
Nareshkumawat-star wants to merge 2 commits into
Dev-Card:mainfrom
Nareshkumawat-star:fix/username-redirects

Conversation

@Nareshkumawat-star

Copy link
Copy Markdown

Summary

This PR implements automatic 301 redirects for public DevCard URLs when a user changes their username. When a username update occurs, the old username is saved in a redirects mapping table. Any subsequent requests visiting the old public profile URL or scanning its QR code are redirected to the new URL for a period of 90 days, ensuring shared links do not break.

Type of Change

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

Closes : #611

What Changed

  • apps/backend/prisma/schema.prisma: Defined the UsernameRedirect model to track the association between old and new usernames.
  • apps/backend/prisma/migrations/20260621223000_add_username_redirects/migration.sql: Added SQL migration for creating the username_redirects table.
  • apps/backend/src/services/profileService.ts: Wrapped the profile update in a transaction to create a redirect record when a username is updated.
  • apps/backend/src/routes/public.ts: Added a preHandler hook to intercept requests with a :username parameter, recursively resolve chained redirects, guard against infinite cycles, and return a 301 redirect.
  • apps/backend/src/__tests__/redirects.test.ts: Added 5 unit tests verifying redirect behavior, expiration limits, multi-step chains, and loop-guard security.
  • apps/web/src/pages/ProfilePage.tsx: Updated browser routing navigation to replace the address bar URL if the fetched profile has a different username.

How to Test

  1. Apply migrations to the database:
    npm --prefix apps/backend run db:migrate

Run the isolated redirects test suite to verify 301 routing, expiration limits, chained redirects, and circular loop-guards:
bash
npx --prefix apps/backend vitest run src/tests/redirects.test.ts
Checklist
My code follows the project's coding style (npm run lint passes).
TypeScript compiles without errors (npm run typecheck --workspaces --if-present).
I have added or updated tests for the changes I made.
All tests pass locally (npm run test --workspaces --if-present).
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.

@vercel

vercel Bot commented Jun 22, 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 github-actions Bot added backend gssoc:approved Required label for every approved PR. Gives the base +50 points and enables contribution tracking. web labels Jun 22, 2026
@github-actions

Copy link
Copy Markdown

Hi @Nareshkumawat-star,

Thanks for opening this pull request.

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

Applied Labels

  • gssoc:approved
  • 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

Copy link
Copy Markdown

CI — Checks Failed

Backend — FAIL

Check Result
Lint FAIL
Test PASS
Typecheck PASS

Mobile — SKIP

Check Result
Lint -
Test -

Web — PASS

Check Result
Build PASS

Last updated: Mon, 22 Jun 2026 17:01:30 GMT

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.

Bug: DevCard public URL returns 404 after username change

1 participant