Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {TextInput,Button} from "react-native-paper";
- import firebase from "../database/firebaseConfig";
- import {View,StyleSheet,Text} from "react-native";
- import {useEffect} from "react";
- import React, { useState } from "react";
- const Login = (props) => {
- const [email,setEmail] = useState('');
- const [password,setPassword] = useState('');
- function loginFirebase(){
- firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
- var errorCode = error.code;
- var errorMessage = error.message;
- alert(errorCode, errorMessage);
- });
- }
- useEffect(()=>{
- firebase.auth().onAuthStateChanged(function(user) {
- if (user) {
- console.log("Logado"+user.uid);
- props.navigation.navigate('Task')
- } else {
- console.log('não logado!')
- }
- });
- },[])
- return (
- <View style={styles.container}>
- <Text style= {styles.title}>Faça login para continuar</Text>
- <TextInput
- mode = "flat"
- style={styles.input}
- placeholder="E-mail"
- value={email}
- onChangeText={email => setEmail(email)}
- />
- <TextInput
- mode = "flat"
- style={styles.input}
- placeholder="Senha"
- // defaultValue={}
- onChangeText={password => setPassword(password)}
- value={password}
- secureTextEntry={true}
- />
- <Button style={styles.loginBtn} mode="contained" onPress={()=>{ loginFirebase()}}>
- Entrar
- </Button>
- </View>
- );
- };
- const styles = StyleSheet.create({
- container:{
- width:'94%',
- marginRight:'2%',
- marginLeft:'2%',
- paddingTop:100
- },
- title: {
- fontSize: 30,
- fontWeight: 'bold',
- color:'#7159C1',
- marginTop: 50,
- marginBottom: 40,
- borderRadius: 10,
- paddingLeft:20,
- },
- input:{
- marginTop:20,
- paddingLeft:10,
- backgroundColor:'whitesmoke',
- },
- loginBtn:{
- marginTop:30,
- width:150,
- alignSelf: 'flex-end'
- }
- });
- export default Login;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement