-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.jsx
61 lines (50 loc) · 1.47 KB
/
index.jsx
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
import styles from './styles';
import {useEffect, useState} from 'react';
import {WebView} from 'react-native-webview';
import {getUniqueId} from 'react-native-device-info';
// Functional component
const SignIn = ({navigation}) => {
// Local states
const [deviceId, setDeviceId] = useState('');
// Declaring an object
const userInfo = {
iss: 'phmail',
aud: 'user',
country_code: '+**',
phone_no: '**********',
};
// Declaring sign-in URL
const URI = `https://auth.phone.email/sign-in?countrycode=${userInfo.country_code}&phone_no=${userInfo.phone_no}&redirect_url=https://dashing-concha-578106.netlify.app/success&auth_type=4&device=${deviceId}`;
// Hooks
useEffect(() => {
// Method to fetch device ID
const fetchDeviceId = async () => {
// Getting unique ID
const id = await getUniqueId();
// Updating state
setDeviceId(id);
// Log the device ID to the console
// console.log('Device ID:', id);
};
fetchDeviceId();
}, []);
const phoneAuthJwt = event => {
// Getting encodedJWT
const encodedJWT = event.nativeEvent.data;
// Navigating to the EmailCount screen with the token param
navigation.navigate('Email Count', {token: encodedJWT});
};
// Returning JSX
return (
<WebView
source={{uri: URI}}
style={styles.webView}
onMessage={phoneAuthJwt}
ref={webView => {
this.webView = webView;
}}
/>
);
};
// Exporting
export default SignIn;