i want to make that when user looks at one post and clicked on Подробнее he is…
- User
i want to make that when user looks at one post and clicked on Подробнее he is redirected to look at more info. Here is my files
import { Text, View, Image, Pressable } from 'react-native'; import { gStyle } from '../styles/style'; import React, {useState, useEffect} from 'react'; import { useNavigation } from '@react-navigation/native'; import {firebase} from '../Firebase/firebase'
export default function FutureMK() { const navigation = useNavigation(); const [posts, setPosts]=useState([]);
useEffect(()=>{ const db=firebase.firestore(); const unsubscribe = db.collection('FutureMK').onSnapshot(snapshot=>{ const newPosts=snapshot.docs.map(doc=>({ id:doc.id, ...doc.data() })); setPosts(newPosts); }); return unsubscribe; },[])return ( date <Image source={require('../assets/example1.jpg')} style={gStyle.FutureMKbannerImg}/> name Цена: price description <Pressable style={gStyle.FutureMKmoreDetails} onPress={()=>{navigation.navigate('SignUpForMK',{post:post});}} > Подробнее ); }
import { Text, View, Image, Pressable, ScrollView } from 'react-native'; import { gStyle } from '../styles/style'; import Header from '../components/Header'; import Footer from '../components/Footer'; import { Ionicons, MaterialCommunityIcons } from '@expo/vector-icons'; import { useNavigation } from '@react-navigation/native'; import { firebase } from '../Firebase/firebase'; import 'firebase/compat/firestore';
export default function SignUpForMK({route}) { const { post } = route.params; const navigation = useNavigation(); return ( {post.name} {post.time} Цена: {post.price} P. {post.description} {post.person} человек {post.timeOfMK} час(а) <Pressable style={gStyle.SupMoreDetails} onPress={()=>navigation.navigate('FormAddMK')} > Записаться ); }
- Assistant
In your
FutureMKcomponent, you need to pass thepostobject to thenavigation.navigatemethod like this:<Pressable style={gStyle.FutureMKmoreDetails} onPress={() => navigation.navigate('SignUpForMK',{ post: post })} > <Text style={gStyle.FutureMKbtnTxt}>Подробнее</Text> </Pressable>Then in your
SignUpForMKcomponent, you can access thepostobject by getting it from theroute.paramsobject:const { post } = route.params;You can then use the
postobject to display more information about the post. - User
ReferenceError: Property 'post' doesn't exist, js engine: hermes
- Assistant
It looks like you didn't pass the
postobject as a prop to yourSignUpForMKcomponent.You need to make sure you pass the
postobject when you navigate from yourFutureMKcomponent by callingnavigation.navigate('SignUpForMK', { post: post }).You should also double-check that you are using the correct variable names and that
postis defined in yourFutureMKcomponent before passing it as a prop toSignUpForMK.If you are still having issues, you can try console.logging
postin yourFutureMKcomponent to make sure that it is defined correctly. - User
- Assistant
It looks like you're passing the
postsarray aspostwhen navigating fromFutureMKtoSignUpForMK. Instead, try passing a single object from thepostsarray that corresponds to the post that was clicked, like this:<Pressable style={gStyle.FutureMKmoreDetails} onPress={() => { navigation.navigate('SignUpForMK', { post: posts[index] }) }} > <Text style={gStyle.FutureMKbtnTxt}>Подробнее</Text> </Pressable>In the code above,
indexis the index of the post on which the user clicked. You'll have to retrieve that value based on user input.Also, make sure that the
postobject in yourSignUpForMKcomponent corresponds to the correct properties in thepostsFirestore collection.Finally, you need to handle cases where the
postobject is null or undefined, which can happen when theSignUpForMKcomponent first renders. You can do this by adding a conditional check onpostin yourSignUpForMKcomponent rendering. - User
[2023-06-06T21:21:52.741Z] @firebase/firestore: Firestore (9.22.1): Uncaught Error in snapshot listener: FirebaseError: [code=permission-denied]: Missing or insufficient permissions.
- Assistant
The error message indicates that the user does not have sufficient permissions to access the Firestore collection.
To fix this issue, you need to modify your Firestore security rules to allow read access to the
FutureMKcollection. You can do this by adding the following rules to your Firestore security rules:service cloud.firestore { match /databases/{database}/documents { match /FutureMK/{document=**} { allow read: if true; allow write: if false; } } }The above rules allow read access to all documents in the
FutureMKcollection. This makes the collection publicly readable, but writable only by an authenticated user. You can adjust the rules to suit your specific use case.Also, make sure that you have initialized Firebase Authentication and that the user is logged in before trying to access the
FutureMKcollection. - User
{ "rules": { "users":{ "uid":{ ".read": "uid===auth.uid", ".write": "$uid===auth.uid" } }, "FutureMK":{ ".read": true, ".write": "root.child('users').child(auth.uid).child('admin').val() === true"
}} }
i had this
- Assistant
The security rules you have provided should allow authenticated users to read the
FutureMKcollection and only allow users with an admin attribute set to true to write to the collection.If you are still receiving the "permission-denied" error, then it's possible that the Firebase Auth user is either not authenticated or does not have the correct role/permissions.
Make sure that you're properly initializing Firebase Auth and logging in the user before attempting to read from or write to the Firestore collection. You can also double-check that the user's role and permissions are set correctly.
- User
how can i set rules that all users even guests can read but only admin write?
- Assistant
You can modify the security rules to allow anyone to read (both authenticated and unauthenticated users) but only allow authenticated users with the
adminattribute set totrueto write.Here's an example of how the rules might look like:
service cloud.firestore { match /databases/{database}/documents { match /FutureMK/{document=**} { allow read: if true; allow write: if request.auth != null && get(/databases/$(database)/documents/users/$(request.auth.uid)).data.admin == true; } } }The
allow read: if true;rule allows anyone to read theFutureMKcollection, while theallow write:rule only allows authenticated users with theadminattribute set totrueto write to the collection.Note that this assumes you have a
userscollection with documents corresponding to each user's UID. Theget(/databases/$(database)/documents/users/$(request.auth.uid)).data.admin == truecondition checks if the authenticated user'sadminattribute is set to in the corresponding document in the collection. You'll need to adjust this based on your own use case. - User
where do i need to write this?
- Assistant
You need to add these security rules to your Firebase project on the Firebase console. Here's how to do it:
- Go to the Firebase console and select your project.
- Click on "Firestore Database" in the left-hand menu.
- Click on the "Rules" tab at the top.
- Replace the existing rules with the rules I provided.
- Click on the "Publish" button to publish the new rules to your database.
After publishing the new rules, your Firestore database should use the new security rules you defined.
Alternatively, you can also update your security rules programmatically using the Firebase CLI. You can find more information in the Firebase documentation.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.