This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"expo": { | |
/...*/ | |
"description": "Basic Firebase Login", | |
"githubUrl": "https://github.com/popeating/FirebaseLogin", | |
/*ADD DATA IN EXTRA SECTION*/ | |
"extra": { | |
"IOS_KEY": "", | |
"ANDROID_KEY": "", | |
"API_KEY": "", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import firebase from 'firebase'; | |
/* Contstants allow to read data from app.json */ | |
import Constants from 'expo-constants'; | |
const firebaseConfig = { | |
apiKey: Constants.manifest.extra.API_KEY, | |
authDomain: Constants.manifest.extra.AUTH_DOMAIN, | |
databaseURL: Constants.manifest.extra.DATABASE_URL, | |
projectId: Constants.manifest.extra.PROJECT_ID, | |
storageBucket: Constants.manifest.extra.STORAGE_BUCKET, | |
messagingSenderId: Constants.manifest.extra.MESSAGE_SENDER_ID, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { createContext } from 'react'; | |
const mainContext = createContext(); | |
export default mainContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { createContext } from 'react'; | |
const mainContext = createContext(); | |
export default mainContext; | |
//In App.js | |
return ( | |
<mainContext.Provider value={mainC}> //mainC will be defined in next step | |
//Resto of code | |
</mainContext.Provider> | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useContext } from 'react'; | |
import { View, StyleSheet } from 'react-native'; | |
import { Text, Button, Title, Paragraph } from 'react-native-paper'; | |
import mainContext from '../context/mainContext'; //Don't forget the context | |
import Firebase from '../Firebase'; | |
import loc from '../utils/localization'; | |
const HomeScreen = () => { | |
const { currentUser } = Firebase.auth(); //we are getting the user from Firebase | |
const { signOutUser } = useContext(mainContext); //we are getting these functions from the context so that can be used here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useContext } from 'react'; | |
import { | |
View, | |
StyleSheet, | |
TouchableWithoutFeedback, | |
Keyboard, | |
} from 'react-native'; | |
import Firebase from '../Firebase'; | |
import { TextInput, Button } from 'react-native-paper'; | |
import loc from '../utils/localization'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from 'react'; | |
import { | |
View, | |
StyleSheet, | |
TouchableWithoutFeedback, | |
Keyboard, | |
} from 'react-native'; | |
import { TextInput, Button } from 'react-native-paper'; | |
import loc from '../utils/localization'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { StatusBar } from 'expo-status-bar'; | |
import React, { useState, useMemo, useEffect } from 'react'; | |
import { Appearance, View } from 'react-native'; | |
//React navigation | |
import { | |
NavigationContainer, | |
DarkTheme, | |
DefaultTheme, | |
} from '@react-navigation/native'; | |
import { createStackNavigator } from '@react-navigation/stack'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//We continue defining our app | |
const App = ({ navigation }) => { | |
//with Hook states we set some initial values (the user profile, if the app is loading, and so on) | |
const [isDarkTheme, setIsDarkTheme] = useState(status); | |
const [userLogged, setUserLogged] = useState(false); | |
const [userProfile, setUserProfile] = useState(null); | |
const [isLoading, setIsLoading] = useState(true); | |
//theme will be the dark or default (defined earlier) based on isDarkTheme | |
const theme = isDarkTheme ? CombinedDarkTheme : CombinedDefaultTheme; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Glogin = async () => { | |
try { | |
//await GoogleSignIn.askForPlayServicesAsync(); | |
const result = await Google.logInAsync({ //return an object with result token and user | |
iosClientId: Constants.manifest.extra.IOS_KEY, //From app.json | |
androidClientId: Constants.manifest.extra.ANDROIUD_KEY, //From app.json | |
}); | |
if (result.type === 'success') { | |
console.log(result); | |
setIsLoading(true); |
OlderNewer