Advertisement
Guest User

Untitled

a guest
Jan 28th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import { StyleSheet, Text, View } from 'react-native';
  3.  
  4. import * as firebase from 'firebase';
  5.  
  6. // Initialize Firebase
  7. const firebaseConfig = {
  8.     // ADD YOUR FIREBASE CREDENTIALS
  9.     apiKey: "",
  10.     authDomain: "",
  11.     databaseURL: "",
  12.     projectId: "",
  13.     storageBucket: "",
  14. };
  15.  
  16. firebase.initializeApp(firebaseConfig);
  17.  
  18. import { Container, Content, Header, Form, Input, Item, Button, Label } from 'native-base'
  19.  
  20. export default class App extends React.Component {
  21.  
  22.     constructor(props) {
  23.         super(props)
  24.  
  25.         this.state = ({
  26.             email: '',
  27.             password: ''
  28.         })
  29.     }
  30.  
  31.     signUpUser = (email, password) => {
  32.  
  33.         try {
  34.  
  35.             if (this.state.password.length < 6) {
  36.                 alert("Please enter atleast 6 characters")
  37.                 return;
  38.             }
  39.  
  40.             firebase.auth().createUserWithEmailAndPassword(email, password)
  41.         }
  42.         catch (error) {
  43.             console.log(error.toString())
  44.         }
  45.     }
  46.  
  47.     loginUser = (email, password) => {
  48.  
  49.         try {
  50.  
  51.             firebase.auth().signInWithEmailAndPassword(email, password).then(function (user) {
  52.                 console.log(user)
  53.  
  54.             })
  55.         }
  56.         catch (error) {
  57.             console.log(error.toString())
  58.         }
  59.     }
  60.  
  61.     render() {
  62.         return (
  63.             <Container style={styles.container}>
  64.                 <Form>
  65.                     <Item floatingLabel>
  66.                         <Label>Email</Label>
  67.                         <Input
  68.                             autoCorrect={false}
  69.                             autoCapitalize="none"
  70.                             onChangeText={(email) => this.setState({ email })}
  71.                         />
  72.  
  73.                     </Item>
  74.  
  75.                     <Item floatingLabel>
  76.                         <Label>Password</Label>
  77.                         <Input
  78.                             secureTextEntry={true}
  79.                             autoCorrect={false}
  80.                             autoCapitalize="none"
  81.                             onChangeText={(password) => this.setState({ password })}
  82.                         />
  83.                     </Item>
  84.  
  85.                     <Button style={{ marginTop: 10 }}
  86.                         full
  87.                         rounded
  88.                         success
  89.                         onPress={() => this.loginUser(this.state.email, this.state.password)}
  90.                     >
  91.                         <Text style={{ color: 'white' }}> Login</Text>
  92.                     </Button>
  93.  
  94.                     <Button style={{ marginTop: 10 }}
  95.                         full
  96.                         rounded
  97.                         primary
  98.                         onPress={() => this.signUpUser(this.state.email, this.state.password)}
  99.                     >
  100.                         <Text style={{ color: 'white' }}> Sign Up</Text>
  101.                     </Button>
  102.  
  103.                 </Form>
  104.             </Container>
  105.         );
  106.     }
  107. }
  108.  
  109. const styles = StyleSheet.create({
  110.     container: {
  111.         flex: 1,
  112.         backgroundColor: '#fff',
  113.         justifyContent: 'center',
  114.         padding: 10
  115.     },
  116. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement