import { Text, View, TextInput, Pressable, ScrollView, Alert, TouchableHighlight,…
- User
import { Text, View, TextInput, Pressable, ScrollView, Alert, TouchableHighlight, TouchableOpacity } from 'react-native'; import { gStyle } from '../styles/style'; import Header from '../components/Header'; import Footer from '../components/Footer'; import { useNavigation } from '@react-navigation/native'; import { firebase } from '../Firebase/firebase'; import 'firebase/compat/auth'; import 'firebase/compat/database'; import 'firebase/compat/firestore'; import React, {useState} from 'react';
export default function Auth() { return (
<Text style={gStyle.header}>Войти в личный{"\n"}кабинет</Text> <View style={gStyle.AuthContainer}> <View style={gStyle.AuthBox}> <View style={gStyle.AuthBox1}> <Text style={gStyle.AuthName}>Почта</Text> <TextInput style={gStyle.AuthInfo} onChangeText={setEmail} /> </View> <View style={gStyle.AuthBox1}> <Text style={gStyle.AuthName}>Пароль</Text> <TextInput style={gStyle.AuthInfo} onChange={setPassword} secureTextEntry={true} /> </View> </View> <Pressable style={gStyle.AuthForgotPassword} onPress={''}> <Text style={gStyle.AuthPass}>Забыли пароль?</Text> </Pressable> <TouchableOpacity style={gStyle.AuthLogin} onPress={handleLogin}> <Text style={gStyle.AuthBtnLogin}>Войти</Text> </TouchableOpacity> <Pressable onPress={()=>navigation.navigate('Registration')} > <Text style={gStyle.AuthRegistr}>Я не зарегистрирован(а)</Text> </Pressable> </View> </View> <Footer/> </ScrollView> </View>); }
write me log in function from firebase
- Assistant
Here is an example of a log in function using Firebase:
const handleLogin = () => { firebase.auth().signInWithEmailAndPassword(email, password) .then((userCredential) => { // Logged in successfully const user = userCredential.user; console.log('User logged in:', user.email); }) .catch((error) => { const errorMessage = error.message; console.log(errorMessage); Alert.alert('Error', errorMessage); }); };In this function,
firebase.auth().signInWithEmailAndPassword(email, password)is used to log in a user with their email and password. The function returns a promise that resolves with auserCredentialobject if the login is successful, or rejects with an error object if there is an error.Inside the
thenblock, we can access the logged-in user throughuserCredential.user. In this example, we are simply logging the user's email to the console.Inside the
catchblock, we handle any errors that may occur during the login process.error.messageis used to retrieve the error message from the error object, and we display it to the user usingAlert.alert(). - User
import { Text, View, Image, Pressable } from 'react-native'; import { gStyle } from '../styles/style'; import React from 'react'; import { useNavigation } from '@react-navigation/native';
export default function FutureMK() { const navigation = useNavigation(); return ( 12:30 12/12/2012 <Image source={require('../assets/example1.jpg')} style={gStyle.FutureMKbannerImg}/> Мастер-класс №1 Цена: 350 P. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut. <Pressable style={gStyle.FutureMKmoreDetails} onPress={()=>{navigation.navigate('SignUpForMK')}} > Подробнее ); }
how can i show data from db? my collection is FutureMK (name, description, price and time)
- Assistant
- User
- Assistant
To show data from your Firebase Firestore database in your
SignUpForMKcomponent, you need to first import the Firebase SDK and set up a listener to theFutureMKcollection on your Firebase Firestore database. Once you have watched the collection and received data in the form of an array of objects, you can pass it down to the component using React Navigation params. Here's an example of how you can achieve this: - User
import { Text, View, Image, Pressable } from 'react-native'; import { gStyle } from '../styles/style'; import React from 'react'; import { useNavigation } from '@react-navigation/native';
export default function FutureMK() { const navigation = useNavigation(); return ( 12:30 12/12/2012 <Image source={require('../assets/example1.jpg')} style={gStyle.FutureMKbannerImg}/> Мастер-класс №1 Цена: 350 P. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut. <Pressable style={gStyle.FutureMKmoreDetails} onPress={()=>{navigation.navigate('SignUpForMK')}} > Подробнее ); }
- Assistant
To allow the user to click on a particular post in the
FutureMKcomponent and navigate to a separate screen with the details about that post, you can use React Navigation.Here are the steps you can follow:
- Modify your
FutureMKcomponent to include a unique identifying property for each post, such as an ID:
export default function FutureMK({ id, name, date, price, description }) { // pass the post's ID as a prop when rendering this component return ( <View style={gStyle.mainFMK}> <Text style={gStyle.dateFutureMK}>{date}</Text> ... <Pressable onPress={() => navigation.navigate('MKDetails', { id })}> <Text style={gStyle.FutureMKbtnTxt}> - Modify your
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.