-
Notifications
You must be signed in to change notification settings - Fork 336
/
Copy pathSignInButton.ts
54 lines (47 loc) · 1.34 KB
/
SignInButton.ts
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
import type { SignInProps } from '@clerk/types';
import { defineComponent, h } from 'vue';
import { useClerk } from '../composables/useClerk';
import { assertSingleChild, normalizeWithDefaultValue } from '../utils';
type SignInButtonProps = Pick<
SignInProps,
'fallbackRedirectUrl' | 'forceRedirectUrl' | '#ForceRedirectUrl' | '#FallbackRedirectUrl' | 'initialValues'
>;
export const SignInButton = defineComponent(
(
props: SignInButtonProps & {
mode?: 'modal' | 'redirect';
},
{ slots, attrs },
) => {
const clerk = useClerk();
function clickHandler() {
const { mode, ...opts } = props;
if (mode === 'modal') {
return clerk.value?.openSignIn(opts);
}
void clerk.value?.redirectToSignIn({
...opts,
signInFallbackRedirectUrl: props.fallbackRedirectUrl,
signInForceRedirectUrl: props.forceRedirectUrl,
});
}
return () => {
const children = normalizeWithDefaultValue(slots.default?.(), '#');
const child = assertSingleChild(children, 'SignInButton');
return h(child, {
...attrs,
onClick: clickHandler,
});
};
},
{
props: [
'#ForceRedirectUrl',
'#FallbackRedirectUrl',
'fallbackRedirectUrl',
'forceRedirectUrl',
'mode',
'initialValues',
],
},
);