/
register.tsx
54 lines (51 loc) 路 1.47 KB
/
register.tsx
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 React from 'react'
import { map, redirect, route } from 'navi'
import { useNavigation } from 'react-navi'
import Form from '../styled/Form'
import { RoutingContext } from '../types/RoutingContext'
import AuthFormLayout from '../styled/AuthFormLayout'
import { colors } from '../utils/theme';
import Firebase from '../Firebase';
export default map<RoutingContext>(({ context }) => {
if (context.currentUser) {
return redirect('/?welcome')
}
else {
return route({
view: <Register firebase={context.firebase} />,
title: 'Register',
})
}
})
function Register({ firebase }: { firebase: Firebase }) {
let navigation = useNavigation()
return (
<AuthFormLayout heading='Register'>
<Form onSubmit={async (value: any) => {
let { email, password } = value
await firebase.auth.createUserWithEmailAndPassword(email, password)
await navigation.navigate('/?welcome')
}}>
<Form.Errors />
<Form.Field
label='Email'
name='email'
validate={value =>
value === '' ? 'Please enter your email.' : undefined
}
/>
<Form.Field
label='Password'
name='password'
type='password'
validate={value =>
value === '' ? 'Please enter your password.' : undefined
}
/>
<Form.SubmitButton bgcolor={colors.red}>
Sign up
</Form.SubmitButton>
</Form>
</AuthFormLayout>
)
}