Skip to content

Commit 2738c7e

Browse files
authored
fix(clerk-js): Handle Last Used SAML strategies (#7135)
1 parent ea65d39 commit 2738c7e

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

.changeset/eleven-phones-say.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
fix: Appropriately handle last-used SAML strategies

integration/tests/last-authentication-strategy.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,28 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })(
7474
await expect(socialButtonContainers.first().locator('.cl-button')).toHaveCount(3);
7575
});
7676

77+
test('should show "Last used" badge when lastAuthenticationStrategy is saml_google', async ({ page, context }) => {
78+
const u = createTestUtils({ app, page, context });
79+
await mockLastAuthenticationStrategyResponse(page, 'saml_google');
80+
81+
await u.po.signIn.goTo();
82+
await u.po.signIn.waitForMounted();
83+
84+
// Ensure "Last used" badge is present.
85+
const lastUsedBadge = page.locator('.cl-lastAuthenticationStrategyBadge');
86+
await expect(lastUsedBadge).toBeVisible();
87+
await expect(lastUsedBadge).toHaveCount(1);
88+
89+
const btn = page.getByRole('button', { name: 'Last used Sign in with Google' });
90+
await expect(btn).toBeVisible();
91+
92+
// Ensure the last used social button has been pulled to the first row.
93+
const socialButtonContainers = u.page.locator('.cl-socialButtons');
94+
await expect(socialButtonContainers).toHaveCount(2);
95+
await expect(socialButtonContainers.first().locator('.cl-button__google')).toHaveCount(1);
96+
await expect(socialButtonContainers.last().locator('.cl-button')).toHaveCount(2);
97+
});
98+
7799
test('should show "Last used" badge when lastAuthenticationStrategy is oauth_google', async ({ page, context }) => {
78100
const u = createTestUtils({ app, page, context });
79101
await mockLastAuthenticationStrategyResponse(page, 'oauth_google');

packages/clerk-js/src/ui/components/SignIn/SignInSocialButtons.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const SignInSocialButtons = React.memo((props: SignInSocialButtonsProps)
3333
return (
3434
<SocialButtons
3535
{...rest}
36-
showLastAuthenticationStrategy={true}
36+
showLastAuthenticationStrategy
3737
idleAfterDelay={!shouldUsePopup}
3838
oauthCallback={strategy => {
3939
if (shouldUsePopup) {

packages/clerk-js/src/ui/elements/SocialButtons.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ export const SocialButtons = React.memo((props: SocialButtonsRootProps) => {
8787
return strategies.includes(strategy as TStrategy);
8888
};
8989

90-
const lastAuthenticationStrategy = clientLastAuth && isValidStrategy(clientLastAuth) ? clientLastAuth : null;
90+
// Convert SAML strategies to OAuth strategies for consistency when matching last used strategy.
91+
const convertedClientLastAuth = clientLastAuth?.startsWith('saml_')
92+
? clientLastAuth.replace('saml_', 'oauth_')
93+
: clientLastAuth;
94+
95+
const lastAuthenticationStrategy =
96+
convertedClientLastAuth && isValidStrategy(convertedClientLastAuth) ? convertedClientLastAuth : null;
9197

9298
const { strategyRows, lastAuthenticationStrategyPresent } = distributeStrategiesIntoRows<TStrategy>(
9399
[...strategies],

0 commit comments

Comments
 (0)