Skip to content
Snippets Groups Projects
Commit cb18c9bb authored by wooshanghyeon's avatar wooshanghyeon
Browse files

Complete examples signUp&In , data CRUD

parent 1a4e2d77
No related branches found
No related tags found
No related merge requests found
......@@ -3,32 +3,59 @@ import React, {useState} from 'react';
import {Text, TextInput, TouchableOpacity, View} from 'react-native';
import {signIn, signUp} from './lib/auth';
import {Alert} from 'react-native';
import {createUser} from './lib/user';
import firestore from '@react-native-firebase/firestore';
import {firebase} from '@react-native-firebase/auth';
const App = () => {
const [email, setEmail] = useState();
const [password, setPass] = useState();
const [displayName, setName] = useState();
const onSignUp = async () => {
console.log(email, password);
try {
const {user} = await signUp({email, password});
console.log(user);
await createUser({
id: user.uid,
displayName,
photoURL: null,
});
Alert.alert('회원가입 성공!');
} catch (e) {
console.log(e);
Alert.alert('회원가입 실패ㅠㅠ');
}
setEmail();
setPass();
setName();
};
const onSignIn = async () => {
console.log(email, password);
try {
const {user} = await signIn({email, password});
console.log(user);
Alert.alert('로그인 성공!.');
const userCollection = firestore().collection('users');
console.log(await userCollection.doc(user.uid).get());
await userCollection.doc(user.uid).update({displayName});
console.log(await userCollection.doc(user.uid).get());
Alert.alert('로그인 성공!');
} catch (e) {
Alert.alert('로그인에 실패ㅠㅠ');
}
setEmail();
setPass();
setName();
};
const onDelete = async () => {
// try {
// const {user} = await signIn({email, password});
// const userCollection = firestore().collection('users');
// await userCollection.doc(user.uid).delete();
// Alert.alert('데이터베이스 삭제 tㅠㅠ');
// } catch (e) {
// Alert.alert('데이터베이스 삭제 실패ㅠㅠ');
// }
// const {user} = await signIn({email, password});
// user.delete().catch(e => {
// console.log(e);
// });
};
return (
<View>
<Text style={{fontSize: 20, fontWeight: 'bold'}}>회원가입 예시</Text>
......@@ -45,6 +72,12 @@ const App = () => {
placeholderTextColor={'black'}
style={{borderColor: 'red', borderBottomWidth: 1}}
/>
<TextInput
onChangeText={setName}
placeholder="displayName"
placeholderTextColor={'black'}
style={{borderColor: 'red', borderBottomWidth: 1}}
/>
<TouchableOpacity onPress={onSignUp}>
<Text>SignUp</Text>
</TouchableOpacity>
......@@ -63,10 +96,34 @@ const App = () => {
placeholderTextColor={'black'}
style={{borderColor: 'red', borderBottomWidth: 1}}
/>
<TextInput
onChangeText={setName}
placeholder="displayName"
placeholderTextColor={'black'}
style={{borderColor: 'red', borderBottomWidth: 1}}
/>
<TouchableOpacity onPress={onSignIn}>
<Text>Login</Text>
</TouchableOpacity>
</View>
<Text style={{fontSize: 20, fontWeight: 'bold'}}>삭제 예시</Text>
<View style={{borderWidth: 3}}>
<TextInput
onChangeText={setEmail}
placeholder="email"
placeholderTextColor={'black'}
style={{borderColor: 'red', borderBottomWidth: 1}}
/>
<TextInput
onChangeText={setPass}
placeholder="password"
placeholderTextColor={'black'}
style={{borderColor: 'red', borderBottomWidth: 1}}
/>
<TouchableOpacity onPress={onDelete}>
<Text>delete</Text>
</TouchableOpacity>
</View>
</View>
);
};
......
......@@ -15,7 +15,7 @@
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:windowSoftInputMode="adjustPan"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment