Skip to content

Commit 45b773a

Browse files
fix(ui): OAuthConsent AuthenticatedRoutes usage (#8327)
1 parent f800b4f commit 45b773a

3 files changed

Lines changed: 45 additions & 29 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/ui': patch
3+
---
4+
5+
Fix OAuthConsent always redirecting to sign-in by adopting the `AuthenticatedRoutes` pattern used by other full-page components

packages/ui/src/components/OAuthConsent/OAuthConsent.tsx

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Header } from '@/ui/elements/Header';
1010
import { LoadingCardContainer } from '@/ui/elements/LoadingCard';
1111
import { Modal } from '@/ui/elements/Modal';
1212
import { Alert, Textarea } from '@/ui/primitives';
13+
import { Route, Switch } from '@/ui/router';
1314

1415
import { InlineAction } from './InlineAction';
1516
import {
@@ -94,41 +95,35 @@ function _OAuthConsent() {
9495

9596
if (errorMessage) {
9697
return (
97-
<Flow.Root flow='oauthConsent'>
98-
<Card.Root>
99-
<Card.Content>
100-
<Card.Alert>{errorMessage}</Card.Alert>
101-
</Card.Content>
102-
<Card.Footer />
103-
</Card.Root>
104-
</Flow.Root>
98+
<Card.Root>
99+
<Card.Content>
100+
<Card.Alert>{errorMessage}</Card.Alert>
101+
</Card.Content>
102+
<Card.Footer />
103+
</Card.Root>
105104
);
106105
}
107106

108107
if (isLoading) {
109108
return (
110-
<Flow.Root flow='oauthConsent'>
111-
<Card.Root>
112-
<Card.Content>
113-
<LoadingCardContainer />
114-
</Card.Content>
115-
<Card.Footer />
116-
</Card.Root>
117-
</Flow.Root>
118-
);
119-
}
120-
}
121-
122-
if (ctx.enableOrgSelection && (!isMembershipsLoaded || userMemberships.isLoading)) {
123-
return (
124-
<Flow.Root flow='oauthConsent'>
125109
<Card.Root>
126110
<Card.Content>
127111
<LoadingCardContainer />
128112
</Card.Content>
129113
<Card.Footer />
130114
</Card.Root>
131-
</Flow.Root>
115+
);
116+
}
117+
}
118+
119+
if (ctx.enableOrgSelection && (!isMembershipsLoaded || userMemberships.isLoading)) {
120+
return (
121+
<Card.Root>
122+
<Card.Content>
123+
<LoadingCardContainer />
124+
</Card.Content>
125+
<Card.Footer />
126+
</Card.Root>
132127
);
133128
}
134129

@@ -155,7 +150,7 @@ function _OAuthConsent() {
155150
const hasOfflineAccess = scopes.some(item => item.scope === OFFLINE_ACCESS_SCOPE);
156151

157152
return (
158-
<Flow.Root flow='oauthConsent'>
153+
<>
159154
<form
160155
method='POST'
161156
action={actionUrl}
@@ -328,7 +323,7 @@ function _OAuthConsent() {
328323
redirectUri={redirectUrl}
329324
oauthApplicationName={oauthApplicationName}
330325
/>
331-
</Flow.Root>
326+
</>
332327
);
333328
}
334329

@@ -373,4 +368,20 @@ function RedirectUriModal({ onOpen, onClose, isOpen, redirectUri, oauthApplicati
373368
);
374369
}
375370

376-
export const OAuthConsent = withCoreUserGuard(withCardStateProvider(_OAuthConsent));
371+
const AuthenticatedRoutes = withCoreUserGuard(withCardStateProvider(_OAuthConsent));
372+
373+
const OAuthConsentInternal = () => {
374+
return (
375+
<Flow.Root flow='oauthConsent'>
376+
<Flow.Part>
377+
<Switch>
378+
<Route>
379+
<AuthenticatedRoutes />
380+
</Route>
381+
</Switch>
382+
</Flow.Part>
383+
</Flow.Root>
384+
);
385+
};
386+
387+
export const OAuthConsent = OAuthConsentInternal;

packages/ui/src/components/OAuthConsent/__tests__/OAuthConsent.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ describe('OAuthConsent', () => {
181181
const getConsentInfo = vi.fn().mockResolvedValue(fakeConsentInfo);
182182
mockOAuthApplication(fixtures.clerk, { getConsentInfo });
183183

184-
const { container } = render(<OAuthConsent />, { wrapper });
184+
const { queryByText } = render(<OAuthConsent />, { wrapper });
185185

186-
expect(container.firstChild).toBeNull();
186+
expect(queryByText('Clerk CLI')).toBeNull();
187187
expect(getConsentInfo).not.toHaveBeenCalled();
188188
});
189189

0 commit comments

Comments
 (0)