-
Notifications
You must be signed in to change notification settings - Fork 80
/
index.js
55 lines (45 loc) · 1.34 KB
/
index.js
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
/**
* @file Login Form.
* @author Vadim Savin
*/
import React, { useState } from 'react';
import { Text, TextInput, Alert } from 'react-native';
import Purchases from 'react-native-purchases';
import styles from './styles';
/*
How to login and identify your users with the Purchases SDK.
These component mimic displaying a login form in order to identifying the user.
Read more about Identifying Users here: https://docs.revenuecat.com/docs/user-ids
*/
const LoginForm = ({ onLogin }) => {
const [newUserId, setNewUserId] = useState('');
console.warn(
"Public-facing usernames aren't optimal for user ID's - you should use something non-guessable, like a non-public database ID. For more information, visit https://docs.revenuecat.com/docs/user-ids.",
);
const login = async () => {
if (!newUserId) {
return;
}
try {
await Purchases.logIn(newUserId);
} catch (e) {
Alert.alert('Error identifying user', e.message);
}
setNewUserId('');
await onLogin();
};
return (
<>
<Text style={styles.headline}>Login</Text>
<TextInput
value={newUserId}
onChangeText={setNewUserId}
onEndEditing={login}
placeholder="Enter App User ID"
placeholderTextColor="lightgrey"
style={styles.input}
/>
</>
);
};
export default LoginForm;