Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 2 additions & 3 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 @@ -1903,6 +1903,7 @@
type ButtonPropsModal<T extends SignInProps | SignUpProps> = {
mode: 'modal';
appearance?: T['appearance'];
unsafeMetadata?: T extends SignUpProps ? SignUpUnsafeMetadata : never;
};

type ButtonPropsRedirect = {
Expand All @@ -1923,9 +1924,7 @@
| 'oauthFlow'
>;

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