-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSignInScreen.tsx
74 lines (66 loc) · 1.9 KB
/
SignInScreen.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import {confirmSignIn, signIn} from 'aws-amplify/auth';
import React from 'react';
import {Image, SafeAreaView, StyleSheet, View} from 'react-native';
import {ErrorCode} from 'react-native-authsignal';
import {Button} from './Button';
import {authsignal} from './config';
import {useAuthContext} from './context';
export function SignInScreen({navigation}: any) {
const {setIsSignedIn} = useAuthContext();
return (
<SafeAreaView style={styles.container}>
<View style={styles.center}>
<Image
source={require('../images/simplify.png')}
resizeMode={'contain'}
style={styles.logo}
/>
<Button
onPress={async () => {
const {data, errorCode} = await authsignal.passkey.signIn({
action: 'cognitoAuth',
});
if (
errorCode === ErrorCode.passkeySignInCanceled ||
errorCode === ErrorCode.noPasskeyCredentialAvailable
) {
return navigation.navigate('SignInEmail');
}
if (data?.username && data?.token) {
await signIn({
username: data.username,
options: {
authFlowType: 'CUSTOM_WITHOUT_SRP',
},
});
const {isSignedIn} = await confirmSignIn({
challengeResponse: data.token,
});
setIsSignedIn(isSignedIn);
}
}}>
Sign in
</Button>
<Button
theme={'secondary'}
onPress={() => navigation.navigate('CreateAccount')}>
Create account
</Button>
</View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
center: {
width: '100%',
},
logo: {
width: '100%',
},
});