0

So i have an error following tutorial on youtube, already try finding on youtube how to fix it but the tutorial show google sign-in but i don't use that function

if anyone can help Thank You Very Much

P.S Still learning firebase so im new here

App.tsx

import React from 'react'
import { StatusBar } from 'expo-status-bar';
import { Alert, StyleSheet, View } from 'react-native';

import { getAuth, createUserWithEmailAndPassword, isSignInWithEmailLink, signInWithEmailAndPassword } from 'firebase/auth'
import {initializeApp} from 'firebase/app'
import { firebaseConfig } from './src/config/firebase';
import { Input, Button, Div, Text } from 'react-native-magnus';

import { NavigationContainer, useNavigation } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';

function HomeScreen(){
  return(
    <Div flex={1} justifyContent='center' alignSelf='center'>
      <Text>Hallo</Text>
    </Div>
  )
}

function LoginScreen(){

  const [email, setEmail] = React.useState('')
  const [password, setPassword] = React.useState('')

  const app = initializeApp(firebaseConfig)
  const auth = getAuth(app)
  
  const nav = useNavigation()

  const handleCreateAccount = () => {
    createUserWithEmailAndPassword(auth, email,password)
    .then((userCredential) => {
      console.log("Account Created")
      const user = userCredential.user
      console.log(user)
    })
    .catch((err) => {
      console.log(err)
      alert(err.message)
    })
  }

  const handleSignIn = () => {
    signInWithEmailAndPassword(auth, email, password)
    .then((userCredential) => {
      console.log("Signed In!") 
      const user = userCredential.user
      console.log(user)
      nav.navigate("Home")
    })
    .catch((err) => {
      console.log(err)
    })
  }

  return(
    <View style={styles.container}>
      <Div w={300}>
        <Input value={email} onChange={(val:any) => setEmail(val) } placeholder='Email..'  />
        <Input value={password} onChange={(val:any) => setPassword(val)} placeholder='Password..' mt={10} />
      </Div>
      <Div justifyContent='center'>
        <Button onPress={handleSignIn} w={100} mt={10}>
          Sign-In
        </Button>
        <Button onPress={handleCreateAccount} w={100} mt={10}>
          Register
        </Button>
      </Div>
      <StatusBar style="auto" />
    </View>
  )
}


const Stack = createNativeStackNavigator()
export default function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen name="Login" component={LoginScreen} options={{headerShown: false}} />
        <Stack.Screen name="Home" component={HomeScreen} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

the error is when i try to register, because u can't login

Michael
  • 73
  • 9
  • 1
    Don't post (personal) API keys/tokens on SO. You should revoke the one in your question. – Andreas Jan 02 '23 at 09:25
  • @Andreas: you might want to check out https://stackoverflow.com/questions/37482366/is-it-safe-to-expose-firebase-apikey-to-the-public/37484053#37484053, as Firebase configuration data is a bit different from API keys you may be used to. I'd still typically not include them in a question, but that's just because they're not needed and are distracting. – Frank van Puffelen Jan 02 '23 at 15:36

1 Answers1

0

This type of error is usually thrown when your machine is not properly connected to the internet.

Try to check internet connectivity on your device and try again !

krishnaacharyaa
  • 14,953
  • 4
  • 49
  • 88