Skip to content
Snippets Groups Projects
Select Git revision
  • cb18c9bb20c113e2d6906e61c2d5f917d42298ec
  • main default protected
2 results

App.js

Blame
  • App.js 4.12 KiB
    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 () => {
        try {
          const {user} = await signUp({email, password});
          await createUser({
            id: user.uid,
            displayName,
            photoURL: null,
          });
          Alert.alert('회원가입 성공!');
        } catch (e) {
          Alert.alert('회원가입 실패ㅠㅠ');
        }
        setEmail();
        setPass();
        setName();
      };
      const onSignIn = async () => {
        try {
          const {user} = await signIn({email, password});
          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>
          <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}}
            />
            <TextInput
              onChangeText={setName}
              placeholder="displayName"
              placeholderTextColor={'black'}
              style={{borderColor: 'red', borderBottomWidth: 1}}
            />
            <TouchableOpacity onPress={onSignUp}>
              <Text>SignUp</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}}
            />
            <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>
      );
    };
    
    export default App;