Skip to content

Comments

feat(dev-tools): add switch user option#142

Merged
BastiDood merged 20 commits intoBastiDood:mainfrom
galierie:dev-tools/switch-user
Feb 19, 2026
Merged

feat(dev-tools): add switch user option#142
BastiDood merged 20 commits intoBastiDood:mainfrom
galierie:dev-tools/switch-user

Conversation

@galierie
Copy link
Contributor

This PR adds the "Switch to Another User" option in the Developer Tools.

@galierie galierie requested a review from BastiDood as a code owner February 19, 2026 10:34
devin-ai-integration[bot]

This comment was marked as resolved.

Copy link
Owner

@BastiDood BastiDood left a comment

Choose a reason for hiding this comment

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

Just a few more nitpicks and correctness issues.

Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View 8 additional findings in Devin Review.

Open in Devin Review

Comment on lines +314 to +316
if (id === null) {
logger.error('failed to switch to another user');
error(404);

Choose a reason for hiding this comment

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

🔴 Server uses error(404) instead of fail(404), so the client-side 'failure' toast is never triggered

When the target user email is not found, the server action calls error(404) at src/routes/dashboard/+page.server.js:316. In SvelteKit, error() throws an HttpError that produces result.type === 'error' in the use:enhance callback. However, the client-side form handler at src/lib/features/dev-tools/user-switcher/form.svelte:36 checks for result.type === 'failure' to display the toast.

Root Cause and Impact

SvelteKit distinguishes between two server-side error mechanisms:

  • error(code)result.type === 'error' → renders +error.svelte page
  • fail(code)result.type === 'failure' → stays on the page, accessible in the enhance callback

The form handler expects 'failure':

case 'failure':
  toast.error('Failed to switch to user.');
  break;

But the server throws error(404), which produces 'error', falling through to the default: break case. Combined with await update() on line 30, this navigates the user to the error page instead of showing a friendly toast. The codebase itself uses fail() elsewhere for recoverable business-logic errors (e.g., src/routes/dashboard/users/+page.server.js:93).

Impact: When a developer enters a non-existent email in the "Switch to Another User" dialog, they are unexpectedly taken to a 404 error page instead of seeing a toast notification.

Prompt for agents
In src/routes/dashboard/+page.server.js, two changes are needed:

1. On line 3, add `fail` to the import from '@sveltejs/kit':
   Change: import { error, redirect } from '@sveltejs/kit';
   To:     import { error, fail, redirect } from '@sveltejs/kit';

2. On line 316, change `error(404)` to `return fail(404)` so the client-side enhance callback receives `result.type === 'failure'` and can display the toast:
   Change: error(404);
   To:     return fail(404);
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Owner

@BastiDood BastiDood left a comment

Choose a reason for hiding this comment

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

Almost there! Sending in my preemptive approval.

@BastiDood BastiDood merged commit 9c1f837 into BastiDood:main Feb 19, 2026
1 check passed
@galierie galierie deleted the dev-tools/switch-user branch February 19, 2026 12:13
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.

2 participants