Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/cyan-pots-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@clerk/astro': patch
'@clerk/clerk-react': patch
'@clerk/types': patch
---

Ensure proper typing for `SignUpButton` and only allow `unsafeMetadata={...}` when `mode="modal"`
18 changes: 7 additions & 11 deletions packages/astro/src/react/SignUpButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,8 @@ export type { SignUpButtonProps };

export const SignUpButton = withClerk(
({ clerk, children, ...props }: WithClerkProp<React.PropsWithChildren<SignUpButtonProps>>) => {
const {
fallbackRedirectUrl,
forceRedirectUrl,
signInFallbackRedirectUrl,
signInForceRedirectUrl,
mode,
unsafeMetadata,
...rest
} = props;
const { fallbackRedirectUrl, forceRedirectUrl, signInFallbackRedirectUrl, signInForceRedirectUrl, mode, ...rest } =
props;

children = normalizeWithDefaultValue(children, 'Sign up');
const child = assertSingleChild(children)('SignUpButton');
Expand All @@ -26,15 +19,18 @@ export const SignUpButton = withClerk(
forceRedirectUrl,
signInFallbackRedirectUrl,
signInForceRedirectUrl,
unsafeMetadata,
};

if (!clerk) {
return;
}

if (mode === 'modal') {
return clerk.openSignUp({ ...opts, appearance: props.appearance });
return clerk.openSignUp({
...opts,
appearance: props.appearance,
unsafeMetadata: props.unsafeMetadata,
});
}

return clerk.redirectToSignUp({
Expand Down
8 changes: 5 additions & 3 deletions packages/react/src/components/SignUpButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const SignUpButton = withClerk(
signInFallbackRedirectUrl,
signInForceRedirectUrl,
mode,
unsafeMetadata,
initialValues,
oauthFlow,
...rest
Expand All @@ -28,13 +27,16 @@ export const SignUpButton = withClerk(
forceRedirectUrl,
signInFallbackRedirectUrl,
signInForceRedirectUrl,
unsafeMetadata,
initialValues,
oauthFlow,
};

if (mode === 'modal') {
return clerk.openSignUp({ ...opts, appearance: props.appearance });
return clerk.openSignUp({
...opts,
appearance: props.appearance,
unsafeMetadata: props.unsafeMetadata,
});
}

return clerk.redirectToSignUp({
Expand Down
18 changes: 10 additions & 8 deletions packages/types/src/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@
*/
windowNavigate: (to: URL | string) => void;
},
) => Promise<unknown> | unknown;

Check warning on line 1111 in packages/types/src/clerk.ts

View workflow job for this annotation

GitHub Actions / Static analysis

'unknown' overrides all other types in this union type

export type WithoutRouting<T> = Omit<T, 'path' | 'routing'>;

Expand Down Expand Up @@ -1900,18 +1900,22 @@
onVerifiedOnOtherDevice?: () => void;
}

type ButtonPropsModal<T extends SignInProps | SignUpProps> = {
type SignInButtonPropsModal = {
mode: 'modal';
appearance?: T['appearance'];
appearance?: SignInProps['appearance'];
};

type SignUpButtonPropsModal = {
mode: 'modal';
appearance?: SignUpProps['appearance'];
unsafeMetadata?: SignUpUnsafeMetadata;
};

type ButtonPropsRedirect = {
mode?: 'redirect';
};

type ButtonProps<T extends SignInProps | SignUpProps> = ButtonPropsModal<T> | ButtonPropsRedirect;

export type SignInButtonProps = ButtonProps<SignInProps> &
export type SignInButtonProps = (SignInButtonPropsModal | ButtonPropsRedirect) &
Pick<
SignInProps,
| 'fallbackRedirectUrl'
Expand All @@ -1923,9 +1927,7 @@
| 'oauthFlow'
>;

export type SignUpButtonProps = {
unsafeMetadata?: SignUpUnsafeMetadata;
} & ButtonProps<SignUpProps> &
export type SignUpButtonProps = (SignUpButtonPropsModal | ButtonPropsRedirect) &
Pick<
SignUpProps,
| 'fallbackRedirectUrl'
Expand Down
Loading