From ba9927fde51df905e9bdc150db72f0b40d0e2ee6 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Mon, 30 Jul 2018 01:19:43 +0300 Subject: [PATCH 1/3] add authentication functionality --- MobileApp/App.js | 3 + MobileApp/config.js | 17 +++++ MobileApp/package.json | 3 +- MobileApp/src/actions/auth.js | 12 ++++ MobileApp/src/components/sign-in.js | 101 +++++++++++++++------------- MobileApp/src/stores/auth.js | 20 ++++-- 6 files changed, 101 insertions(+), 55 deletions(-) create mode 100644 MobileApp/config.js create mode 100644 MobileApp/src/actions/auth.js diff --git a/MobileApp/App.js b/MobileApp/App.js index 481462b..249fe0d 100644 --- a/MobileApp/App.js +++ b/MobileApp/App.js @@ -3,11 +3,14 @@ import {configure} from 'mobx' import {Provider} from 'mobx-react' import AppNavigator from './src/components/app-navigator' import stores from './src/stores' +import firebaseInit from './config' configure({ enforceActions: true }) +firebaseInit() + export default class App extends React.Component { render() { return ( diff --git a/MobileApp/config.js b/MobileApp/config.js new file mode 100644 index 0000000..653db78 --- /dev/null +++ b/MobileApp/config.js @@ -0,0 +1,17 @@ +import { initializeApp } from 'firebase/app' +import 'firebase/auth' +import 'firebase/database' + +export const appName = 'advreact-25-06' + +const config = { + apiKey: 'AIzaSyBnWMvhTYPpwSnVwYvrWTrsS7TlHwu1wHg', + authDomain: 'advreact-25-06.firebaseapp.com', + databaseURL: 'https://advreact-25-06.firebaseio.com', + projectId: 'advreact-25-06', + storageBucket: '', + messagingSenderId: '371151529375' +} + + +export default () => initializeApp(config) \ No newline at end of file diff --git a/MobileApp/package.json b/MobileApp/package.json index e7187b5..bd93e6e 100644 --- a/MobileApp/package.json +++ b/MobileApp/package.json @@ -3,8 +3,8 @@ "version": "0.1.0", "private": true, "devDependencies": { - "react-native-scripts": "1.14.0", "jest-expo": "~27.0.0", + "react-native-scripts": "1.14.0", "react-test-renderer": "16.3.1" }, "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js", @@ -21,6 +21,7 @@ "dependencies": { "email-validator": "^2.0.4", "expo": "^27.0.1", + "firebase": "^5.3.0", "lodash": "^4.17.10", "mobx": "^5.0.3", "mobx-react": "^5.2.3", diff --git a/MobileApp/src/actions/auth.js b/MobileApp/src/actions/auth.js new file mode 100644 index 0000000..d759706 --- /dev/null +++ b/MobileApp/src/actions/auth.js @@ -0,0 +1,12 @@ +import firebase from 'firebase/app' +import stores from '../stores' + +export const LoggedIn = (email, password) => { + const firebaseAuth = firebase.auth() + const { auth } = stores + return firebaseAuth.signInWithEmailAndPassword(email, password) + .then(({user})=> auth.setUser(user)) + .catch((e) => console.error(e)) +} + + diff --git a/MobileApp/src/components/sign-in.js b/MobileApp/src/components/sign-in.js index 812285e..ea05f19 100644 --- a/MobileApp/src/components/sign-in.js +++ b/MobileApp/src/components/sign-in.js @@ -1,67 +1,74 @@ import React, { Component } from 'react' import {View, TextInput, Text, Button, Platform} from 'react-native' import {observer, inject} from 'mobx-react' +import {LoggedIn} from '../actions/auth' @inject('navigation', 'auth') @observer class SignIn extends Component { - static propTypes = { + static propTypes = { - }; + }; - render() { - const { email, password, isValidEmail } = this.props.auth - return ( - - - Email: - - - - {isValidEmail ? '' : 'Not a valid email'} - - - Password: - - -