Skip to content

Commit fae192f

Browse files
chore(clerk-js): Only render last used badge on sign-in (#7100)
1 parent 2587aa6 commit fae192f

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

.changeset/heavy-badgers-beam.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+
Remove last used badge from rendering on sign-up.

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,18 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })(
115115
await expect(socialButtonContainers).toHaveCount(1);
116116
await expect(socialButtonContainers.first().locator('.cl-button')).toHaveCount(3);
117117
});
118+
119+
test('should not show "Last used" badge on sign-up even when lastAuthenticationStrategy is set', async ({
120+
page,
121+
context,
122+
}) => {
123+
const u = createTestUtils({ app, page, context });
124+
await mockLastAuthenticationStrategyResponse(page, 'oauth_google');
125+
126+
await u.po.signUp.goTo();
127+
await u.po.signUp.waitForMounted();
128+
129+
await expect(page.locator('.cl-lastAuthenticationStrategyBadge')).toHaveCount(0);
130+
});
118131
},
119132
);

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

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

packages/clerk-js/src/ui/components/SignUp/SignUpSocialButtons.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const SignUpSocialButtons = React.memo((props: SignUpSocialButtonsProps)
3232
return (
3333
<SocialButtons
3434
{...rest}
35+
showLastAuthenticationStrategy={false}
3536
idleAfterDelay={!shouldUsePopup}
3637
oauthCallback={(strategy: OAuthStrategy) => {
3738
if (shouldUsePopup) {

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type SocialButtonsRootProps = SocialButtonsProps & {
4141
web3Callback: (strategy: Web3Strategy) => Promise<unknown>;
4242
alternativePhoneCodeCallback: (channel: PhoneCodeChannel) => void;
4343
idleAfterDelay?: boolean;
44+
showLastAuthenticationStrategy?: boolean;
4445
};
4546

4647
const isWeb3Strategy = (val: string): val is Web3Strategy => {
@@ -60,6 +61,7 @@ export const SocialButtons = React.memo((props: SocialButtonsRootProps) => {
6061
enableWeb3Providers = true,
6162
enableAlternativePhoneCodeProviders = true,
6263
idleAfterDelay = true,
64+
showLastAuthenticationStrategy = false,
6365
} = props;
6466
const { web3Strategies, authenticatableOauthStrategies, strategyToDisplayData, alternativePhoneCodeChannels } =
6567
useEnabledThirdPartyProviders();
@@ -79,7 +81,14 @@ export const SocialButtons = React.memo((props: SocialButtonsRootProps) => {
7981
return null;
8082
}
8183

82-
const lastAuthenticationStrategy = clerk.client?.lastAuthenticationStrategy as TStrategy | null;
84+
const clientLastAuth = showLastAuthenticationStrategy ? clerk.client?.lastAuthenticationStrategy : null;
85+
86+
const isValidStrategy = (strategy: unknown): strategy is TStrategy => {
87+
return strategies.includes(strategy as TStrategy);
88+
};
89+
90+
const lastAuthenticationStrategy = clientLastAuth && isValidStrategy(clientLastAuth) ? clientLastAuth : null;
91+
8392
const { strategyRows, lastAuthenticationStrategyPresent } = distributeStrategiesIntoRows<TStrategy>(
8493
[...strategies],
8594
MAX_STRATEGIES_PER_ROW,

0 commit comments

Comments
 (0)