Advertisement
IcaroPeretti

LoginScreen

May 12th, 2021
1,206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {TextInput,Button} from "react-native-paper";
  2. import firebase from "../database/firebaseConfig";
  3. import {View,StyleSheet,Text} from "react-native";
  4. import {useEffect} from "react";
  5. import React, { useState } from "react";
  6.  
  7.  
  8. const Login = (props) => {
  9.     const [email,setEmail] = useState('');
  10.     const [password,setPassword] = useState('');
  11.  
  12.    function loginFirebase(){
  13.     firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
  14.       var errorCode = error.code;
  15.       var errorMessage = error.message;
  16.       alert(errorCode, errorMessage);
  17.     });
  18.   }
  19.  
  20.  
  21.   useEffect(()=>{
  22.     firebase.auth().onAuthStateChanged(function(user) {
  23.       if (user) {
  24.        console.log("Logado"+user.uid);
  25.        props.navigation.navigate('Task')
  26.       } else {
  27.         console.log('não logado!')
  28.       }
  29.     });
  30.   },[])
  31.  
  32.  
  33.     return (
  34.         <View style={styles.container}>
  35.         <Text style= {styles.title}>Faça login para continuar</Text>
  36.             <TextInput
  37.                 mode = "flat"
  38.                 style={styles.input}
  39.                 placeholder="E-mail"
  40.                 value={email}
  41.                 onChangeText={email => setEmail(email)}
  42.             />
  43.  
  44.             <TextInput
  45.                 mode = "flat"
  46.                 style={styles.input}
  47.                 placeholder="Senha"
  48.                 // defaultValue={}
  49.                 onChangeText={password => setPassword(password)}  
  50.                 value={password}
  51.                 secureTextEntry={true}
  52.             />      
  53.                
  54.             <Button style={styles.loginBtn} mode="contained" onPress={()=>{ loginFirebase()}}>
  55.                 Entrar
  56.             </Button>
  57.            
  58.         </View>
  59.     );
  60. };
  61.  
  62. const styles = StyleSheet.create({
  63.     container:{
  64.       width:'94%',
  65.       marginRight:'2%',
  66.       marginLeft:'2%',
  67.       paddingTop:100
  68.     },
  69.     title: {
  70.         fontSize: 30,
  71.         fontWeight: 'bold',
  72.         color:'#7159C1',
  73.         marginTop: 50,
  74.         marginBottom: 40,
  75.         borderRadius: 10,
  76.         paddingLeft:20,
  77.     },
  78.     input:{
  79.       marginTop:20,
  80.       paddingLeft:10,
  81.       backgroundColor:'whitesmoke',
  82.     },
  83.     loginBtn:{
  84.         marginTop:30,
  85.         width:150,
  86.         alignSelf: 'flex-end'
  87.     }
  88.   });
  89.  
  90. export default Login;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement