Skip to content

Fixed 401 error on the frontend side if it failed to fetch /api/@me.#155

Merged
breadddevv merged 1 commit into
mainfrom
fix/login
Jun 19, 2026
Merged

Fixed 401 error on the frontend side if it failed to fetch /api/@me.#155
breadddevv merged 1 commit into
mainfrom
fix/login

Conversation

@breadddevv

@breadddevv breadddevv commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling for login failures with field-specific error messages for invalid credentials
    • Enhanced OAuth redirect error messaging with clearer feedback
    • Refined username availability checking and error state management
    • Fixed loading state handling to prevent stale updates
  • Style

    • Reformatted login UI for improved readability and consistency

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

pages/login.tsx receives both functional fixes and broad JSX reformatting. Functional changes include an isMounted-guarded useEffect that sets --group-theme and logs background fetch errors, field-specific react-hook-form errors in onSubmitLogin keyed by HTTP status, improved username debounce cleanup, and an explicit else-if OAuth error handler that clears query params via Router.replace. All other edits are multi-line JSX and clsx reformatting with no behavioral changes.

Changes

Login Page – Logic Fixes and Reformatting

Layer / File(s) Summary
Auth loading, login errors, username debounce, OAuth error routing
pages/login.tsx
useEffect adds isMounted guard, sets --group-theme CSS variable, and logs background fetch errors. onSubmitLogin sets react-hook-form field errors by HTTP status (404/401/other) and rethrows so finally clears loading. Username change handler cancels the pending timeout and clears errors before rescheduling checkUsernameAvailability. OAuth error useEffect uses explicit else if branches and calls Router.replace to remove handled error params.
JSX and formatting cleanup
pages/login.tsx
SVG spinner, avatar palette, state declarations, OAuth buttons, divider, background overlay, heading, main login/signup card, verification UI, and Dialog were all expanded to multi-line JSX with clsx usage. No behavioral changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 A rabbit tidied up the den,
Fixed errors—login works again!
The theme now paints the background right,
Debounce cancels with delight.
OAuth cleans its query string,
All neatly wrapped in formatting. ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title addresses only a specific error case (/api/@me fetch failure) but the changeset includes substantial refactoring of login UI, auth error handling, OAuth redirect errors, and username availability checking—making the title too narrow for the scope of changes. Revise the title to reflect the broader refactoring scope, such as 'Refactor login page auth flows and error handling' or similar, to accurately represent all substantive changes in the PR.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/login

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

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

⚠️ Outside diff range comments (1)
pages/login.tsx (1)

366-389: ⚠️ Potential issue | 🟠 Major

Switch to useRouter() for reactive OAuth error handling.

Line 367 uses the singleton Router object in the effect dependency array, which does not guarantee React's proper reactivity tracking. The effect can miss the isReady transition and skip error toast/query cleanup during navigation. Use the useRouter() hook instead, which is the documented pattern for Pages Router and ensures proper reactive subscription.

Proposed fix
-import Router from "next/router";
+import { useRouter } from "next/router";

 const Login: NextPage = () => {
+  const router = useRouter();
   // ...

   useEffect(() => {
-    if (!Router.isReady || errorToastShown.current) return;
-    const { error, action, ...rest } = Router.query;
+    if (!router.isReady || errorToastShown.current) return;
+    const { error, action, ...rest } = router.query;
     if (error) {
       // ...toast branches...
       errorToastShown.current = true;
-      Router.replace({ pathname: Router.pathname, query: rest }, undefined, {
+      router.replace({ pathname: router.pathname, query: rest }, undefined, {
         shallow: true,
       });
     }
-  }, [Router.isReady, Router.query]);
+  }, [router.isReady, router.query, router.pathname, router.replace]);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pages/login.tsx` around lines 366 - 389, The useEffect hook is using the
singleton Router object instead of the useRouter() hook, which prevents proper
reactive tracking of state changes. Replace all references to the singleton
Router with a Router reference obtained from calling useRouter() at the
component level. This ensures the effect properly subscribes to Router state
changes and executes when Router.isReady transitions or Router.query is updated,
allowing the error toast and query cleanup logic to execute correctly during
navigation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@pages/login.tsx`:
- Around line 366-389: The useEffect hook is using the singleton Router object
instead of the useRouter() hook, which prevents proper reactive tracking of
state changes. Replace all references to the singleton Router with a Router
reference obtained from calling useRouter() at the component level. This ensures
the effect properly subscribes to Router state changes and executes when
Router.isReady transitions or Router.query is updated, allowing the error toast
and query cleanup logic to execute correctly during navigation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d0085c87-88c3-468f-841a-fdec70888ddf

📥 Commits

Reviewing files that changed from the base of the PR and between 7f2c36d and 75ae98c.

📒 Files selected for processing (1)
  • pages/login.tsx

@breadddevv breadddevv merged commit fbe0ec0 into main Jun 19, 2026
5 checks passed
@breadddevv breadddevv deleted the fix/login branch June 19, 2026 16:54
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.

1 participant