DEV Community

Cover image for React native App firebase email authentication signup
sreehari k
sreehari k

Posted on

React native App firebase email authentication signup

`
function Login({ navigation }) {

const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [emailPlaceholder, setEmailPlaceholder]=useState('Email id');
const [passworPlaceholder, setPasswordPlaceholder]=useState('Password');

const signup = () => {
    if(email !='' && password !=''){
        auth().createUserWithEmailAndPassword(email, password).then((res)=>{
            navigation.navigate('Home')
            console.log('response', res)
        })
        .catch((error)=>{
            console.log('Error:', error);
            Alert.alert(error.message);
        })
    }else if(email == ''){
        // Alert.alert('email cannot be empty')
        setEmailPlaceholder('email cannot be empty')
    }else if(password == ''){
        setPasswordPlaceholder('password cannot be empty')
    }
}

const login = () => {
    auth().signInWithEmailAndPassword(email,password).then((res)=>{
        navigation.navigate('Home')
        console.log('response', res)
    }).catch((error)=>{
        console.log('error',error)
    })
}

return (
    <View style={styles.container}>
        <TextInput style={styles.userInput} placeholder={emailPlaceholder}
            placeholderTextColor={'#3e4f6b'} value={email}
            onChangeText={setEmail} keyboardType='email-address' />

        <TextInput style={styles.userInput} placeholder={passworPlaceholder}
            placeholderTextColor={'#3e4f6b'} value={password}
            onChangeText={setPassword} secureTextEntry={true} />

        <View style={styles.buttonView}>
            <TouchableHighlight style={styles.button}
                onPress={signup} >
                <Text style={styles.buttonText}>Sign up</Text>
            </TouchableHighlight>
            <TouchableHighlight style={styles.button}
                onPress={login}>
                <Text style={styles.buttonText}>Login</Text>
            </TouchableHighlight>
        </View>

    </View>
)
Enter fullscreen mode Exit fullscreen mode

}
`

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay