mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-11-03 07:25:47 +00:00
New users arriving at /auth/connect (e.g. from OpenCode CLI) had no organization yet, causing the 'Approve Connection' button to silently fail. The handleConnect guard 'if (!session || !org) return' would fire with no feedback, leading to rage-clicking. Changes: - Detect logged-in users with no org on the connect page and redirect them to onboarding, stashing the connect URL in sessionStorage. - After onboarding completes (skip or finish), redirect back to the connect page so the plugin auth flow finishes automatically. - Show an error message instead of silently returning when session/org is missing and the user clicks 'Approve Connection'. - Wait for full auth state before showing the connect card. - Extract PENDING_CONNECT_URL_KEY and consumePendingConnectUrl() to a shared constants file with 7 unit tests.
28 lines
1 KiB
TypeScript
28 lines
1 KiB
TypeScript
/**
|
|
* sessionStorage key used to stash the full plugin-connect URL so that
|
|
* the onboarding flow can redirect back to it after the user creates
|
|
* their first organization.
|
|
*/
|
|
export const PENDING_CONNECT_URL_KEY = "supermemory-pending-connect-url"
|
|
|
|
/**
|
|
* Consume the pending plugin-connect URL from sessionStorage (if any)
|
|
* and return the relative path to redirect to. Returns `null` when
|
|
* there is nothing stored or the stored value is invalid.
|
|
*
|
|
* This is extracted into a shared helper so that every onboarding
|
|
* completion / skip path can reuse it (SetupHeader, IntegrationsStep,
|
|
* InitialHeader, etc.).
|
|
*/
|
|
export function consumePendingConnectUrl(): string | null {
|
|
try {
|
|
const pendingUrl = sessionStorage.getItem(PENDING_CONNECT_URL_KEY)
|
|
if (!pendingUrl) return null
|
|
sessionStorage.removeItem(PENDING_CONNECT_URL_KEY)
|
|
const parsed = new URL(pendingUrl)
|
|
return parsed.pathname + parsed.search + parsed.hash
|
|
} catch (e) {
|
|
console.warn("Failed to access sessionStorage for pending connect URL", e)
|
|
return null
|
|
}
|
|
}
|