admin管理员组

文章数量:1122832

I’m working on a SvelteKit app using Supabase, Auth.js, and a HubSpot OAuth integration. I want to disconnect the HubSpot OAuth connection when a new user logs in (normal logins are handled by supabase). However, when I try to call signOut (to disconnect HubSpot) during the login process, it interferes with the login redirect.

Here’s my current code:

const onLogin = async (event: SubmitEvent) => {
    event.preventDefault();

    const form = event.currentTarget as HTMLFormElement;
    const data = new FormData(form);

    $loginQuery.mutate(data, {
        onSuccess: async () => {
            createToast({
                message: "Logged in",
                type: 'info'
            });

            // Attempt to disconnect OAuth after login
            await signOut({ redirect: undefined });
        },
        onError: (error) => {
            createToast({
                message: error.message || "Failed to log in, check your info!",
                type: 'error'
            });
        }
    });
};

Problem:

  1. If I call signOut right after the login mutation (outside the onSuccess), it interferes with the redirect and breaks the login process. The user just stays on the Login page and has to login in a second time. Then it works (because the OAuth was disconnected).
  2. If I move the signOut call into the onSuccess callback and make it async, it does nothing—the HubSpot connection remains active.

What I’ve Tried:

  • Calling signOut asynchronously in the onSuccess callback.
  • Delaying the redirect until after the signOut completes.
  • Explicitly passing { redirect: false } to signOut.

None of these approaches have worked. The signOut either doesn’t execute as expected or conflicts with the redirect.

Question:

  1. Is there another way to disconnect the HubSpot OAuth session using Auth.js that avoids this conflict?
  2. How can I reliably disconnect the HubSpot OAuth session after a new user logs in without breaking the login flow or the redirect?

Tech Stack:

  • SvelteKit
  • Supabase
  • Hooks for redirects
  • Auth.js
  • HubSpot OAuth

本文标签: typescriptDisconnecting OAuth connection in the backgroundStack Overflow