Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(oauth): show "Redirecting…" screen after authorize (#57877)

Rafael Audibertc3aa479413c3
diff --git a/frontend/src/scenes/oauth/OAuthAuthorize.tsx b/frontend/src/scenes/oauth/OAuthAuthorize.tsx
index f4edb4c04927..8fbed1c2dfa4 100644
--- a/frontend/src/scenes/oauth/OAuthAuthorize.tsx
+++ b/frontend/src/scenes/oauth/OAuthAuthorize.tsx
@@ -10,6 +10,7 @@ import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { LemonInput } from 'lib/lemon-ui/LemonInput'
import { LemonLabel } from 'lib/lemon-ui/LemonLabel/LemonLabel'
import { LemonSelect } from 'lib/lemon-ui/LemonSelect'
+import { Link } from 'lib/lemon-ui/Link'
import { Spinner } from 'lib/lemon-ui/Spinner'
import { organizationLogic } from 'scenes/organizationLogic'
import ScopeAccessSelector from 'scenes/settings/user/scopes/ScopeAccessSelector'
@@ -42,6 +43,30 @@ export const OAuthAuthorizeSuccess = ({ appName }: { appName: string }): JSX.Ele
)
}
+export const OAuthAuthorizeRedirecting = ({
+ appName,
+ redirectUrl,
+}: {
+ appName: string
+ redirectUrl: string
+}): JSX.Element => {
+ return (
+ <div className="flex flex-col items-center justify-center h-full gap-4 py-12 px-4">
+ <Spinner className="text-3xl" />
+ <div className="text-xl font-semibold">Redirecting to {appName}…</div>
+ <div className="text-sm text-muted text-center max-w-md">
+ <p>This usually only takes a moment.</p>
+ <p className="mt-2">
+ Not redirected automatically? <Link to={redirectUrl}>Click here</Link>.
+ </p>
+ <p className="mt-2">
+ If {appName} has already finished authorizing on your end, you can safely close this window.
+ </p>
+ </div>
+ </div>
+ )
+}
+
const InlineCreateForm = ({
label,
placeholder,
@@ -108,6 +133,8 @@ export const OAuthAuthorize = (): JSX.Element => {
redirectDomain,
requiredAccessLevel,
authorizationComplete,
+ isRedirecting,
+ redirectUrl,
scopesWereDefaulted,
isMcpResource,
resourceScopesLoading,
@@ -193,6 +220,10 @@ export const OAuthAuthorize = (): JSX.Element => {
return <OAuthAuthorizeSuccess appName={oauthApplication.name} />
}
+ if (isRedirecting) {
+ return <OAuthAuthorizeRedirecting appName={oauthApplication.name} redirectUrl={redirectUrl} />
+ }
+
return (
<div className="min-h-full overflow-y-auto">
<div className="max-w-2xl mx-auto py-8 px-4 sm:py-12 sm:px-6">
diff --git a/frontend/src/scenes/oauth/oauthAuthorizeLogic.ts b/frontend/src/scenes/oauth/oauthAuthorizeLogic.ts
index ceb52fc576a0..2dd01bd93bdd 100644
--- a/frontend/src/scenes/oauth/oauthAuthorizeLogic.ts
+++ b/frontend/src/scenes/oauth/oauthAuthorizeLogic.ts
@@ -33,10 +33,11 @@ const isNativeProtocol = (url: string): boolean => {
}
}
+type OAuthAuthorizeResult = { redirectTo: string; isNative: boolean }
+
const oauthAuthorize = async (
- values: OAuthAuthorizationFormValues & { allow: boolean; scopes: string[] },
- onNativeRedirectComplete?: () => void
-): Promise<void> => {
+ values: OAuthAuthorizationFormValues & { allow: boolean; scopes: string[] }
+): Promise<OAuthAuthorizeResult | null> => {
try {
const response = await api.create('/oauth/authorize/', {
client_id: router.values.searchParams['client_id'],
@@ -56,21 +57,17 @@ const oauthAuthorize = async (
})
if (response.redirect_to) {
- const isNative = isNativeProtocol(response.redirect_to)
- location.href = response.redirect_to
-
- if (isNative && onNativeRedirectComplete) {
- // Small delay to ensure redirect is initiated before showing success
- setTimeout(() => onNativeRedirectComplete(), 100)
+ return {
+ redirectTo: response.redirect_to,
+ isNative: isNativeProtocol(response.redirect_to),
}
}
+ return null
} catch (error: any) {
const detail = error?.detail || error?.message || 'Something went wrong while authorizing the application'
lemonToast.error(detail)
throw error
}
-
- return
}
export const oauthAuthorizeLogic = kea<oauthAuthorizeLogicType>([
@@ -88,6 +85,7 @@ export const oauthAuthorizeLogic = kea<oauthAuthorizeLogicType>([
cancel: () => ({}),
setCanceling: (canceling: boolean) => ({ canceling }),
setAuthorizationComplete: (complete: boolean) => ({ complete }),
+ setRedirecting: (redirectUrl: string) => ({ redirectUrl }),
setSelectedOrganization: (organizationId: string, preferredTeamId?: number) => ({
organizationId,
preferredTeamId,
@@ -131,13 +129,16 @@ export const oauthAuthorizeLogic = kea<oauthAuthorizeLogicType>([
cancel: async () => {
actions.setCanceling(true)
try {
- await oauthAuthorize({
+ const result = await oauthAuthorize({
scoped_organizations: values.oauthAuthorization.scoped_organizations,
scoped_teams: values.oauthAuthorization.scoped_teams,
access_type: values.oauthAuthorization.access_type,
allow: false,
scopes: values.scopes,
})
+ if (result) {
+ location.href = result.redirectTo
+ }
} finally {
actions.setCanceling(false)
}
@@ -235,6 +236,18 @@ export const oauthAuthorizeLogic = kea<oauthAuthorizeLogicType>([
setAuthorizationComplete: (_, { complete }) => complete,
},
],
+ isRedirecting: [
+ false,
+ {
+ setRedirecting: () => true,
+ },
+ ],
+ redirectUrl: [
+ '',
+ {
+ setRedirecting: (_, { redirectUrl }) => redirectUrl,
+ },
+ ],
selectedOrganization: [
null as string | null,
{
@@ -314,14 +327,25 @@ export const oauthAuthorizeLogic = kea<oauthAuthorizeLogicType>([
}),
submit: async (values: OAuthAuthorizationFormValues) => {
const scopes = oauthAuthorizeLogic.values.scopes
- await oauthAuthorize(
- {
- ...values,
- allow: true,
- scopes,
- },
- () => actions.setAuthorizationComplete(true)
- )
+ const result = await oauthAuthorize({
+ ...values,
+ allow: true,
+ scopes,
+ })
+ if (!result) {
+ return
+ }
+ // Swap the form for a "Redirecting…" view so the user sees progress
+ // while the browser navigates — for HTTP loopback redirects (Cursor,
+ // Claude Code, etc.) the browser may sit waiting for the local
+ // listener to respond, which makes the original screen feel hung.
+ actions.setRedirecting(result.redirectTo)
+ location.href = result.redirectTo
+ if (result.isNative) {
+ // Native protocol handlers (vscode://, cursor://, etc.) don't
+ // navigate the browser away; show success after a brief delay.
+ setTimeout(() => actions.setAuthorizationComplete(true), 100)
+ }
},
},
})),