forked from clerk/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignUpButton.ts
More file actions
56 lines (49 loc) · 1.37 KB
/
Copy pathSignUpButton.ts
File metadata and controls
56 lines (49 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import type { SignUpProps } from '@clerk/types';
import { defineComponent, h } from 'vue';
import { useClerk } from '../composables/useClerk';
import { assertSingleChild, normalizeWithDefaultValue } from '../utils';
type SignUpButtonProps = {
unsafeMetadata?: SignUpUnsafeMetadata;
} & Pick<
SignUpProps,
'fallbackRedirectUrl' | 'forceRedirectUrl' | 'signInForceRedirectUrl' | 'signInFallbackRedirectUrl'
>;
export const SignUpButton = defineComponent(
(
props: SignUpButtonProps & {
mode?: 'modal' | 'redirect';
},
{ slots, attrs },
) => {
const clerk = useClerk();
function clickHandler() {
const { mode, ...opts } = props;
if (mode === 'modal') {
return clerk.value?.openSignUp(opts);
}
void clerk.value?.redirectToSignUp({
...opts,
signUpFallbackRedirectUrl: props.fallbackRedirectUrl,
signUpForceRedirectUrl: props.forceRedirectUrl,
});
}
return () => {
const children = normalizeWithDefaultValue(slots.default?.(), 'Sign up');
const child = assertSingleChild(children, 'SignUpButton');
return h(child, {
...attrs,
onClick: clickHandler,
});
};
},
{
props: [
'unsafeMetadata',
'signInForceRedirectUrl',
'signInFallbackRedirectUrl',
'fallbackRedirectUrl',
'forceRedirectUrl',
'mode',
],
},
);