Aucune description

App.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import React, { Component } from 'react';
  2. import firebase from 'firebase'
  3. import { NavigationContainer } from '@react-navigation/native';
  4. import { createStackNavigator } from '@react-navigation/stack';
  5. import RegisterScreen from './screens/RegisterScreen';
  6. import LoginScreen from './screens/LoginScreen';
  7. import { firebaseConfig } from './config/firebaseConfig';
  8. import { Text, View } from 'react-native';
  9. import { styles } from './config/styles';
  10. /*const seConfig = {
  11. apiKey: "AIzaSyDW-ABAQ3r_WR7C7WC_3VprL77NcAoitJI",
  12. authDomain: "freehand-d8ecd.firebaseapp.com",
  13. projectId: "freehand-d8ecd",
  14. storageBucket: "freehand-d8ecd.appspot.com",
  15. messagingSenderId: "48371388186",
  16. appId: "1:48371388186:web:9a5a4bf1218e17ac6326a3"
  17. };
  18. */
  19. // Initialize Firebase
  20. //const app = firebase.initializeApp(seConfig);
  21. if (firebase.apps.length === 0) {
  22. firebase.initializeApp(firebaseConfig)
  23. }
  24. const Stack = createStackNavigator();
  25. export default class App extends Component {
  26. constructor(props){
  27. super(props);
  28. this.state = {
  29. loaded: false,
  30. }
  31. }
  32. componentDidMount(){
  33. firebase.auth().onAuthStateChanged((user) => {
  34. if (!user){
  35. this.setState({
  36. loggedIn: false,
  37. loaded: true,
  38. })
  39. }
  40. else{
  41. this.setState({
  42. loggedIn: true,
  43. loaded: true,
  44. })
  45. }
  46. })
  47. }
  48. render() {
  49. const { loggedIn, loaded } = this.state
  50. if(!loaded){
  51. return(
  52. <View style={styles.regcontainer}>
  53. <Text>Hopper</Text>
  54. </View>
  55. );
  56. }
  57. if(!loggedIn){
  58. return (
  59. <NavigationContainer>
  60. <Stack.Navigator>
  61. <Stack.Screen name={" "} options={{headerShown: false}} component={LoginScreen}/>
  62. <Stack.Screen name={"Register"} options={{headerTransparent: true, headerTitle: " "}} component={RegisterScreen}/>
  63. </Stack.Navigator>
  64. </NavigationContainer>
  65. );
  66. }
  67. return(
  68. <View style={styles.regcontainer}>
  69. <Text>Cheese</Text>
  70. </View>
  71. );
  72. }
  73. }