Skip to content

Commit 6dbe00d

Browse files
viva-jinyiclaude
andauthored
fix: prevent logged-in users from accessing login page unless switching accounts (#6478)
## Summary - Prevents logged-in users from viewing the login page unnecessarily - Adds explicit account switching flow with query parameter - Fixes issue where logged-in users could see the login page when directly navigating to `/cloud/login` ## Changes 1. Added `beforeEnter` guard to `cloud-login` route to check authentication status 2. Redirect authenticated users to `cloud-user-check` (which handles survey, waitlist, and main page routing) 3. Added `switchAccount` query parameter to allow intentional access to login page for account switching 4. Updated CloudClaimInviteView and CloudWaitlistView to include the `switchAccount` parameter when users click "Switch accounts" 5. Reverted UserCheckView to use `window.location.href = '/'` instead of `router.replace('/')` to prevent infinite loading issue ## Context The change in UserCheckView reverts to the original implementation (`window.location.href = '/'`) because using `router.replace('/')` caused an infinite loading issue. The direct window navigation avoids the router's internal state issues and ensures a clean redirect to the main application. ## Test plan - [ ] Navigate to `/cloud/login` while logged in → Should redirect to appropriate page - [ ] Click "Switch accounts" from waitlist or invite views → Should stay on login page - [ ] Complete login flow → Should redirect properly based on user status - [ ] Verify no infinite loading occurs when redirecting to main app 🤖 Generated with [Claude Code](https://claude.ai/code) ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6478-fix-prevent-logged-in-users-from-accessing-login-page-unless-switching-accounts-29d6d73d3650815a9d98c11951425241) by [Unito](https://www.unito.io) Co-authored-by: Claude <[email protected]>
1 parent daa9aff commit 6dbe00d

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

src/onboardingCloudRoutes.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,23 @@ export const cloudOnboardingRoutes: RouteRecordRaw[] = [
1616
path: 'login',
1717
name: 'cloud-login',
1818
component: () =>
19-
import('@/platform/onboarding/cloud/CloudLoginView.vue')
19+
import('@/platform/onboarding/cloud/CloudLoginView.vue'),
20+
beforeEnter: async (to, _from, next) => {
21+
// Only redirect if not explicitly switching accounts
22+
if (!to.query.switchAccount) {
23+
const { useCurrentUser } = await import(
24+
'@/composables/auth/useCurrentUser'
25+
)
26+
const { isLoggedIn } = useCurrentUser()
27+
28+
if (isLoggedIn.value) {
29+
// User is already logged in, redirect to user-check
30+
// user-check will handle survey, waitlist, or main page routing
31+
return next({ name: 'cloud-user-check' })
32+
}
33+
}
34+
next()
35+
}
2036
},
2137
{
2238
path: 'signup',

src/platform/onboarding/cloud/CloudClaimInviteView.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ const inviteCode = computed(() => route.query.inviteCode as string)
9898
const onSwitchAccounts = () => {
9999
void router.push({
100100
name: 'cloud-login',
101-
query: { inviteCode: inviteCode.value }
101+
query: {
102+
switchAccount: 'true',
103+
inviteCode: inviteCode.value
104+
}
102105
})
103106
}
104107
const onClickSupport = () => {

src/platform/onboarding/cloud/CloudWaitlistView.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ const router = useRouter()
5252
5353
const onSwitchAccounts = () => {
5454
void router.push({
55-
name: 'cloud-login'
55+
name: 'cloud-login',
56+
query: { switchAccount: 'true' }
5657
})
5758
}
5859

src/platform/onboarding/cloud/UserCheckView.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const {
8080
}
8181
8282
// User is fully onboarded (active or whitelist check disabled)
83-
await router.replace('/')
83+
window.location.href = '/'
8484
}),
8585
null,
8686
{ resetOnExecute: false }

0 commit comments

Comments
 (0)