Skip to content

Bugbot test - #5

Closed
smb060606 wants to merge 4 commits into
mainfrom
feat/user-auth-ui-improvements
Closed

Bugbot test#5
smb060606 wants to merge 4 commits into
mainfrom
feat/user-auth-ui-improvements

Conversation

@smb060606

@smb060606 smb060606 commented Dec 10, 2025

Copy link
Copy Markdown
Collaborator

Note

Implements Bluesky auth endpoints that upsert users in Supabase and set session cookies, adds logout and health checks, enhances match/compare UI and methodology docs, and introduces Bugbot rules.

  • Auth & Sessions
    • Endpoints: POST /api/auth/bsky/create-challenge and POST /api/auth/bsky/verify-challenge with improved validation/messages; verification clears challenge, upserts user, and sets session cookie.
    • Session Utils: src/lib/auth/session.ts to read/clear session; new POST /api/auth/logout to clear cookie.
    • User Service: src/lib/services/userService.ts to resolve DID via Bluesky, fetch profile, and upsert/select users in Supabase.
  • Database
    • Migration supabase/migrations/005_create_users.sql creating public.users (indexes, RLS, updated_at trigger).
  • Operations
    • Health Check: GET /api/health reporting overall/database/Bluesky status with version.
  • UI/UX
    • src/routes/match/[id]/+page.svelte and src/routes/compare/[matchId]/+page.svelte: show "Accounts Used" with DID tooltips; better error handling/messages; loading spinner; minor tab/tooltip styling; copy tweaks.
    • src/routes/methodology/+page.svelte: expanded eligibility and transparency sections.
  • Docs
    • bugbot.md: rules for auth flow, exclusions (migrations), and JS style enforcement.

Written by Cursor Bugbot for commit 9f26122. This will update automatically on new commits. Configure here.

- Add users table migration for Bluesky-authenticated users
- Implement user service with getOrCreateUser and getUserByHandle
- Complete verify-challenge endpoint to create users and sessions
- Add session management helpers (getSession, clearSession)
- Add logout endpoint
- Enhance accounts used display on match and compare pages
- Improve methodology page with account selection transparency
- Add health check endpoint (/api/health)
- Improve error messages throughout with actionable guidance
- Add loading states and spinners for async operations
- Add better error styling and user feedback
@coderabbitai

coderabbitai Bot commented Dec 10, 2025

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/user-auth-ui-improvements

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

@smb060606

Copy link
Copy Markdown
Collaborator Author

@BugBot run

httpOnly: true,
secure: process.env.NODE_ENV === 'production',
sameSite: 'lax',
maxAge: 60 * 60 * 24 * 30 // 30 days

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Session cookie is unsigned allowing session forgery

The session cookie stores user identity data (userId, handle, verifiedAt) as plain JSON without cryptographic signing or encryption. An attacker can forge a valid session by crafting their own cookie with any userId and handle values, allowing impersonation of any user. The getSession function only validates that the required fields exist, not that the cookie was issued by the server. Session cookies should be signed (e.g., using HMAC) or use encrypted JWTs to prevent tampering and forgery.

Additional Locations (1)

Fix in Cursor Fix in Web

headers: { 'Content-Type': 'application/json' }
}
);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Challenge cleared before user creation can fail

The clearChallenge(handle) call happens before getOrCreateUser(handle) is executed. If user creation fails (returns null due to Supabase being unconfigured or database errors), the challenge has already been cleared. The user cannot retry verification and must request a new challenge and post a new verification code publicly on Bluesky. The challenge should only be cleared after user creation succeeds.

Fix in Cursor Fix in Web

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@BugBot what is the user facing implication if I do not implement this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@cursor what is the user facing implication if I do not implement this?

@cursor cursor Bot Dec 10, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looking at the bug report about "Challenge cleared before user creation can fail," here's the user-facing implication if you don't fix this:

Scenario: A user tries to verify their Bluesky account. They post the verification code to their Bluesky profile, and then submit it to your app. However, your database (Supabase) is temporarily down or misconfigured.

What happens:

  1. Your code clears their verification challenge immediately
  2. Then it tries to create the user in the database
  3. The database operation fails
  4. The user gets an error message
  5. The problem: They can't retry! Their challenge code is already cleared, so even though they still have the verification post on Bluesky, they'll get a "challenge not found" error if they try again

User impact:

  • The user must start the entire verification flow from scratch
  • They need to create a NEW verification challenge
  • They need to post a NEW verification code publicly on their Bluesky profile (creating clutter)
  • Poor user experience during any database hiccups

In practice: This is particularly frustrating because users naturally assume they should be able to retry the same verification they already posted publicly. The bug makes transient failures (network issues, database timeouts) permanently consume verification attempts.

The fix is simple: move the clearChallenge() call to after the getOrCreateUser() succeeds, so challenges are only cleared when verification actually completes successfully.


Open in Cursor Open in Web

Learn more about Cursor Agents

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@cursor - create a rule in bugbot.md and never recommend this type of comment again. I am ok with user re-trying with a new verification code.

@cursor cursor Bot Dec 10, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I've created a bugbot.md file at the root of your workspace with a rule that tells Bugbot not to flag this pattern as a bug. The rule clearly states that:

  1. Clearing verification challenges before user creation completes is intentional in your codebase
  2. Requiring users to get a new verification code if user creation fails is an acceptable UX trade-off
  3. This specific pattern should not be flagged as requiring the challenge to be cleared only after successful user creation

Bugbot should respect this rule in future analyses and not report this type of issue again.


Open in Cursor Open in Web

Learn more about Cursor Agents

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@cursor add a rule to that bugbot.md file and filter out reviews for any database migration files in this entire repo

@cursor cursor Bot Dec 10, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I've updated the bugbot.md file to add a new rule that excludes database migration files from Bugbot's analysis. The rule specifies:

  • Paths to exclude: supabase/migrations/**/*.sql and any file matching **/migrations/**/*.sql
  • Rationale: Migration files are historical records that shouldn't be modified after being applied to production, so any issues should be addressed through new migrations rather than flagging existing ones

Bugbot should now skip analyzing all database migration files in the repository and won't report any bugs found in them.


Open in Cursor Open in Web

Learn more about Cursor Agents

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@cursor add a rule to bugbot.md to always check for code compliance with javascript style guide for .js files in src folder in this repo

@cursor cursor Bot Dec 10, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I've added a new rule to the bugbot.md file for JavaScript style guide compliance. The rule specifies:

  • Scope: All .js files within src/**/*.js
  • Style guidelines: Enforces consistent indentation, semicolons, quotes, function formatting, spacing, ES6+ features, and naming conventions
  • Rationale: Maintains consistent code style to improve readability and prevent bugs

Bugbot should now actively check JavaScript files in the src/ folder for compliance with standard JavaScript style guidelines and report any violations.


Open in Cursor Open in Web

Learn more about Cursor Agents

@cursor

cursor Bot commented Dec 10, 2025

Copy link
Copy Markdown

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

Co-authored-by: anitabansal.flights <anitabansal.flights@gmail.com>
}

// Basic handle validation
if (!handle.includes('.') && !handle.includes('@')) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Invalid handle format passes validation check

The handle validation logic !handle.includes('.') && !handle.includes('@') incorrectly allows handles that contain an @ but no dot, such as @example. Valid Bluesky handles must contain a domain separator (.), like example.bsky.social. The @ prefix is optional decoration, not a substitute for the required domain structure. A handle like @invalid would pass this check despite being malformed.

Fix in Cursor Fix in Web

health.status = 'degraded';
}

const statusCode = health.status === 'down' ? 503 : health.status === 'degraded' ? 200 : 200;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Health endpoint status code contradicts documentation

The JSDoc comment on line 18 states "Returns 200 if healthy, 503 if degraded/down" but the actual status code logic at line 81 returns 200 for both degraded and ok states, only returning 503 for down. This mismatch means monitoring systems and load balancers expecting 503 on degraded states will not detect service degradation as documented.

Additional Locations (1)

Fix in Cursor Fix in Web

Co-authored-by: anitabansal.flights <anitabansal.flights@gmail.com>
}
)
.select()
.single();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Upsert overwrites existing user data when API fails

When resolveDidFromHandle fails (due to network issues or Bluesky API unavailability), it returns null, causing did, displayName, and avatarUrl to all be null. The upsert then overwrites these columns with null values for existing users, erasing previously stored profile data. A returning user who re-authenticates during a temporary API outage would lose their DID, display name, and avatar. The upsert should either skip updating these fields when the API call fails, or only update them when new values are successfully retrieved.

Fix in Cursor Fix in Web

Co-authored-by: anitabansal.flights <anitabansal.flights@gmail.com>
health.services.database = 'down';
health.status = 'degraded';
hasErrors = true;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Health check skips database connectivity test for anon client

The health check has inconsistent database verification logic. When the admin client is available, it actually queries the database to verify connectivity. However, when falling back to the anon client (lines 42-48), it only checks whether the client object exists, without testing actual database connectivity. This means the health endpoint can report database: 'ok' even when the database is unreachable, as long as the Supabase anon client was successfully instantiated. This could mislead load balancers and monitoring systems into routing traffic to unhealthy instances.

Fix in Cursor Fix in Web

@smb060606 smb060606 closed this Dec 11, 2025
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