-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathsignup.tsx
More file actions
89 lines (81 loc) · 2.47 KB
/
signup.tsx
File metadata and controls
89 lines (81 loc) · 2.47 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { Link, Text, Flex } from '@raystack/apsara';
import React, { ComponentPropsWithRef, useCallback } from 'react';
import { useFrontier } from '~/react/contexts/FrontierContext';
import { useQuery, useMutation, FrontierServiceQueries } from '~hooks';
import { Container } from '../Container';
import { Header } from '../Header';
import { MagicLink } from './magiclink';
import { OIDCButton } from './oidc';
// @ts-ignore
import styles from './onboarding.module.css';
type SignUpProps = ComponentPropsWithRef<typeof Container> & {
logo?: React.ReactNode;
title?: string;
excludes?: string[];
};
export const SignUp = ({
logo,
title = 'Create your account',
excludes = [],
...props
}: SignUpProps) => {
const { config } = useFrontier();
const { data: strategiesData } = useQuery(
FrontierServiceQueries.listAuthStrategies
);
const strategies = strategiesData?.strategies || [];
const { mutateAsync: authenticate } = useMutation(
FrontierServiceQueries.authenticate
);
const clickHandler = useCallback(
async (name?: string) => {
if (!name) return;
try {
const response = await authenticate({
strategyName: name,
callbackUrl: config.callbackUrl
});
if (response.endpoint) {
window.location.href = response.endpoint;
}
} catch (error) {
console.error('Authentication failed:', error);
}
},
[authenticate, config.callbackUrl]
);
const mailotp = strategies.find(s => s.name === 'mailotp');
const filteredOIDC = strategies
.filter(s => s.name !== 'mailotp')
.filter(s => !excludes.includes(s.name ?? ''));
return (
<Container {...props}>
<Header logo={logo} title={title} />
<Flex direction="column" gap={3} width="full">
{filteredOIDC.map((s, index) => {
return (
<OIDCButton
key={index}
onClick={() => clickHandler(s.name)}
provider={s.name || ''}
data-test-id="frontier-sdk-signup-page-oidc-btn"
></OIDCButton>
);
})}
{mailotp && <MagicLink />}
</Flex>
<div style={{ fontWeight: '400' }}>
<Text size="small">
Already have an account?{' '}
<Link
href={config.redirectLogin || ''}
className={styles.redirectLink}
data-test-id="frontier-sdk-login-btn"
>
Login
</Link>
</Text>
</div>
</Container>
);
};