Skip to content

fix: preserve page context via cookie after Bluesky redirect#930

Open
NandkishorJadoun wants to merge 8 commits intonpmx-dev:mainfrom
NandkishorJadoun:fix/preserve-current-page-context
Open

fix: preserve page context via cookie after Bluesky redirect#930
NandkishorJadoun wants to merge 8 commits intonpmx-dev:mainfrom
NandkishorJadoun:fix/preserve-current-page-context

Conversation

@NandkishorJadoun
Copy link
Contributor

fixes #901

Previously, users logging in via Bluesky were redirected to the homepage regardless of which page they started from.

@vercel
Copy link

vercel bot commented Feb 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs.npmx.dev Error Error Feb 5, 2026 4:53am
npmx.dev Ready Ready Preview, Comment Feb 5, 2026 4:53am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
npmx-lunaria Ignored Ignored Feb 5, 2026 4:53am

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 4, 2026

📝 Walkthrough

Walkthrough

The client component now uses the current route (useRoute) and replaces direct auth redirects with navigateTo calls to /api/auth/atproto, including query parameters handle, optional create, and returnTo set to route.fullPath. The server endpoint accepts a returnTo query, validates it as a safe relative path (falls back to / if invalid), stores it in an auth_return_to cookie with a 5‑minute maxAge (httpOnly; secure toggled in development), and after completing OAuth/session handling reads and deletes that cookie to redirect the user to the preserved path.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description is directly related to the changeset, clearly stating it fixes issue #901 by preserving page context after Bluesky login redirects.
Linked Issues check ✅ Passed The code changes directly address the linked issue #901 by implementing return context preservation through cookies and the navigateTo mechanism with returnTo parameters.
Out of Scope Changes check ✅ Passed All changes are scoped to the Bluesky authentication flow and return context preservation, with no unrelated modifications detected outside the stated objectives.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/components/Header/AuthModal.client.vue (1)

26-36: ⚠️ Potential issue | 🟠 Major

Missing returnTo parameter in handleLogin creates inconsistent redirect behaviour.

The handleLogin() function for manual handle input does not include the returnTo query parameter, whilst handleBlueskySignIn() and handleCreateAccount() do. Users logging in with a custom handle will be redirected to the homepage instead of their original page.

🐛 Proposed fix to add returnTo parameter
 async function handleLogin() {
   if (handleInput.value) {
     await navigateTo(
       {
         path: '/api/auth/atproto',
-        query: { handle: handleInput.value },
+        query: { handle: handleInput.value, returnTo: route.fullPath },
       },
       { external: true },
     )
   }
 }

@danielroe
Copy link
Member

would you mind resolving the conflicts? 🙏

/* Individual symbol articles */
.docs-content .docs-symbol {
@apply mb-10 pb-10 border-b border-border/30 last:border-0;
word-break: break-word;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it have to do with the described fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was working on another issue and forgot to switch branches. Please ignore that commit for now

@NandkishorJadoun
Copy link
Contributor Author

yeah, working on it

Copy link
Contributor

@wojtekmaj wojtekmaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Listen to the rabbit 🐰

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@wojtekmaj wojtekmaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from the style change that sneaked in, LGTM.

const query = getQuery(event)
const rawReturnTo = query.returnTo?.toString() || '/'
// Validate returnTo is a safe relative path (prevent open redirect)
const isRelativePath = rawReturnTo.startsWith('/') && !rawReturnTo.startsWith('//') && !rawReturnTo.includes(':')
Copy link
Member

@danielroe danielroe Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be safer to construct a new URL, validate the hostname, and pass this to setCookie

@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
app/components/Header/AuthModal.client.vue 33.33% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/components/Header/AuthModal.client.vue (1)

29-33: ⚠️ Potential issue | 🟠 Major

Custom handle login does not preserve page context.

The handleLogin function uses authRedirect(handleInput.value) without passing the returnTo parameter. Users who enter a custom handle will be redirected to the homepage after authentication, inconsistent with the other two login flows (handleBlueskySignIn and handleCreateAccount) which both pass returnTo: route.fullPath.

The authRedirect function currently accepts only identifier and optional create parameters, and does not include returnTo in its query object. Update the function signature to accept an optional returnTo parameter:

-export async function authRedirect(identifier: string, create: boolean = false) {
+export async function authRedirect(identifier: string, create: boolean = false, returnTo?: string) {
   let query: LocationQueryRaw = { handle: identifier }
   if (create) {
     query = { ...query, create: 'true' }
   }
+  if (returnTo) {
+    query = { ...query, returnTo }
+  }
   await navigateTo(
     {
       path: '/api/auth/atproto',
       query,
     },
     { external: true },
   )
 }

Then call it with the return path in handleLogin:

 async function handleLogin() {
   if (handleInput.value) {
-    await authRedirect(handleInput.value)
+    await authRedirect(handleInput.value, false, route.fullPath)
   }
 }

Copy link
Contributor

@fatfingers23 fatfingers23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for adding it! Was a big ask we got

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Login via Atmosphere account redirects to Homepage instead of preserving current page context

4 participants