Skip to content

Commit

Permalink
feat(clerk-js,clerk-react,types): Add unsafeMetadata prop to <SignUp />
Browse files Browse the repository at this point in the history
Fixes USR-99
  • Loading branch information
tmilewski committed Jul 18, 2023
1 parent 73c0f9a commit 2a9d832
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 8 deletions.
7 changes: 7 additions & 0 deletions .changeset/angry-spies-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@clerk/clerk-js': minor
'@clerk/clerk-react': minor
'@clerk/types': minor
---

Add unsafeMetadata prop to <SignUp />
1 change: 1 addition & 0 deletions packages/clerk-js/src/ui/Components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ const Components = (props: ComponentsProps) => {

componentsControls.mountComponent = params => {
const { node, name, props, appearanceKey } = params;

assertDOMElement(node);
setState(s => {
s.nodes.set(node, { key: `p${++portalCt}`, name, props, appearanceKey });
Expand Down
6 changes: 5 additions & 1 deletion packages/clerk-js/src/ui/components/SignUp/SignUpStart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function _SignUpStart(): JSX.Element {
const { attributes } = userSettings;
const { setActive } = useCoreClerk();
const ctx = useSignUpContext();
const { navigateAfterSignUp, signInUrl } = ctx;
const { navigateAfterSignUp, signInUrl, unsafeMetadata } = ctx;
const [activeCommIdentifierType, setActiveCommIdentifierType] = React.useState<ActiveIdentifier>(
getInitialActiveIdentifier(attributes, userSettings.signUp.progressive),
);
Expand Down Expand Up @@ -182,6 +182,10 @@ function _SignUpStart(): JSX.Element {
[] as Array<FormControlState>,
);

if (unsafeMetadata) {
fieldsToSubmit.push({ id: 'unsafeMetadata', value: unsafeMetadata } as any);
}

if (fields.ticket) {
const noop = () => {
//
Expand Down
6 changes: 4 additions & 2 deletions packages/react/src/components/SignUpButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import { assertSingleChild, normalizeWithDefaultValue, safeExecute } from '../ut
import { withClerk } from './withClerk';

export const SignUpButton = withClerk(({ clerk, children, ...props }: WithClerkProp<SignUpButtonProps>) => {
const { afterSignInUrl, afterSignUpUrl, redirectUrl, mode, ...rest } = props;
const { afterSignInUrl, afterSignUpUrl, redirectUrl, mode, unsafeMetadata, ...rest } = props;

children = normalizeWithDefaultValue(children, 'Sign up');
const child = assertSingleChild(children)('SignUpButton');

const clickHandler = () => {
const opts = { afterSignInUrl, afterSignUpUrl, redirectUrl };
const opts = { afterSignInUrl, afterSignUpUrl, redirectUrl, unsafeMetadata };

if (mode === 'modal') {
return clerk.openSignUp(opts);
}

return clerk.redirectToSignUp(opts);
};

Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ type ButtonProps = {
};

export type SignInButtonProps = ButtonProps;
export type SignUpButtonProps = ButtonProps;
export interface SignUpButtonProps extends ButtonProps {
unsafeMetadata?: SignUpUnsafeMetadata;
}

export type SignInWithMetamaskButtonProps = Pick<ButtonProps, 'redirectUrl' | 'children'>;

Expand Down
5 changes: 5 additions & 0 deletions packages/types/src/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,11 @@ export type SignUpProps = {
* prop of ClerkProvided (if one is provided)
*/
appearance?: SignUpTheme;

/**
* Additional arbitrary metadata to be stored alongside the User object
*/
unsafeMetadata?: SignUpUnsafeMetadata;
} & RedirectOptions;

export type UserProfileProps = {
Expand Down
2 changes: 1 addition & 1 deletion playground/nextjs/app/app-dir/sign-up/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SignUp } from '@clerk/nextjs/app-beta';

export default function Page() {
return <SignUp />;
return <SignUp unsafeMetadata={{ playground: 'nextjs', type: 'app-dir' }} />;
}
3 changes: 1 addition & 2 deletions playground/nextjs/pages/sign-up/[[...index]].tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { SignUp } from '@clerk/nextjs';
import type { NextPage } from 'next';
import React from 'react';

const SignUpPage: NextPage = () => {
return (
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
<SignUp />
<SignUp unsafeMetadata={{ playground: 'nextjs', type: 'pages' }} />
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion playground/vanillajs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ <h3>Clerk JS Playground</h3>
}

function openSignUp() {
Clerk.openSignUp();
Clerk.openSignUp({ unsafeMetadata: { playground: 'vanillajs' } });
}

function signOut() {
Expand Down

0 comments on commit 2a9d832

Please sign in to comment.