Fix/username redirects#638
Open
Nareshkumawat-star wants to merge 2 commits into
Open
Conversation
|
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. |
|
Thanks for opening this pull request. This PR has been automatically classified based on the files modified. Applied Labels
Primary Review Area
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! |
CI — Checks FailedBackend — FAIL
Mobile — SKIP
Web — PASS
Last updated: |
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.
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
Closes : #611
What Changed
apps/backend/prisma/schema.prisma: Defined theUsernameRedirectmodel to track the association between old and new usernames.apps/backend/prisma/migrations/20260621223000_add_username_redirects/migration.sql: Added SQL migration for creating theusername_redirectstable.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 apreHandlerhook to intercept requests with a:usernameparameter, 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
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.