Skip to content

Refresh user after linking account#256

Open
GioLogist wants to merge 2 commits intomainfrom
B3-2625-re-authenticate-after-accountlink
Open

Refresh user after linking account#256
GioLogist wants to merge 2 commits intomainfrom
B3-2625-re-authenticate-after-accountlink

Conversation

@GioLogist
Copy link
Collaborator

[LINEAR_ISSUE_ID_HERE]

Description

Write a description.

Test Plan

  • Locally
  • Unit Tests
  • Manually
  • CI/CD

Screenshots

For BE, include snippets, response payloads and/or curl commands to test endpoints

[FE] Before

[FE] After

[BE] Snippets/Response/Curl


automerge=false

@GioLogist GioLogist requested a review from a team as a code owner September 30, 2025 22:30
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @GioLogist, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a critical enhancement to the account linking process by ensuring that a user's authentication state is immediately refreshed upon successful linkage. This change addresses potential issues with stale user data, providing a more consistent and reliable user experience by reflecting the most current profile information across the application.

Highlights

  • User Authentication Refresh: After successfully linking an account, the user's authentication state is now automatically refreshed to ensure up-to-date profile information.
  • Robust Authentication Flow: The refresh mechanism first attempts to re-authenticate the user; if that fails, it performs a fresh authentication to guarantee a valid session.
  • Improved Debugging: Added debug logging to trace the authentication process during account linking, aiding in troubleshooting and development.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds logic to refresh the user's authentication state after linking a new account. The changes introduce a new onSuccess handler that attempts to re-authenticate the user, with a fallback to a fresh authentication flow. My review focuses on improving the reliability of this new logic by addressing missing dependencies in a useCallback hook, ensuring the user state is correctly updated after authentication, and adding proper error handling to prevent unhandled promise rejections.

Comment on lines 120 to 133
const onSuccess = useCallback(async () => {
// Update user on success
// Try to re-authenticate first
try {
const userAuth = await app.reAuthenticate();
setUser(userAuth.user);
} catch (error) {
// If re-authentication fails, try fresh authentication
debug("Re-authentication failed, attempting fresh authentication");
const userAuth = await authenticate(account as Account, partnerId);
debug("Fresh authentication successful", { userAuth });
}
await onSuccessCallback?.();
}, [onSuccessCallback]);
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The onSuccess callback has a few issues that could lead to bugs:

  1. Stale closures: The useCallback dependency array is missing setUser, account, authenticate, and partnerId. This can cause the callback to use stale values for these variables.
  2. State not updated: After a successful fresh authentication, the user state is not updated with setUser(). The new user information is fetched but then discarded.
  3. Unhandled errors: If the fresh authenticate() call fails, the error is not caught, which will result in an unhandled promise rejection.

I've suggested a refactor to address these points.

  const onSuccess = useCallback(async () => {
    // Update user on success
    try {
      // Try to re-authenticate first
      const userAuth = await app.reAuthenticate();
      setUser(userAuth.user);
    } catch (reAuthError) {
      // If re-authentication fails, try fresh authentication
      debug("Re-authentication failed, attempting fresh authentication", reAuthError);
      try {
        if (account) {
          const userAuth = await authenticate(account, partnerId);
          setUser(userAuth.user);
          debug("Fresh authentication successful", { userAuth });
        }
      } catch (authError) {
        debug("Fresh authentication also failed", authError);
      }
    }
    await onSuccessCallback?.();
  }, [onSuccessCallback, setUser, account, authenticate, partnerId]);

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