I'm fairly new to programming as well as Flutter/Firebase, but I'm making progress in understanding it. My goal is to create an app that integrates user and location data using Firebase, allowing me to display multiple user locations on a map. What I really need assistance with is figuring out how to write the Firebase UID and user location information within the same Firestore document using a Typescript cloud function.
Over the past few months, I've been experimenting with this Firebase background location plugin and have gained significant insights into its functionality. In parallel, I've been exploring various Firebase Auth templates to understand the available API options. The crucial realization for me has been the importance of the UID as the primary identifier for my users.
Additionally, I've delved into Firebase cloud functions and learned how to efficiently write specific data to a Firestore collection. Using a Javascript cloud function, I managed to store user information along with their UID in a collection, while a Typescript cloud function allowed me to save location details (latitude, longitude, etc.) successfully.
Below is the Typescript code snippet that contains the essential location data. I'm now wondering if there's a way to modify this script to also include additional details like the UID or email address obtained from the user data stored in Firebase. Any suggestions on advancing further would be highly appreciated. Thank you for taking the time to read this. Nathan
import * as functions from 'firebase-functions';
exports.createLocation = functions.firestore
.document('locations/{locationId}')
.onCreate((snap, context) => {
const record = snap.data();
const location = record.location;
console.log('[data] - ', record);
return snap.ref.set({
uuid: location.uuid,
timestamp: location.timestamp,
is_moving: location.is_moving,
latitude: location.coords.latitude,
longitude: location.coords.longitude,
speed: location.coords.speed,
heading: location.coords.heading,
altitude: location.coords.altitude,
event: location.event,
battery_is_charging: location.battery.is_charging,
battery_level: location.battery.level,
activity_type: location.activity.type,
activity_confidence: location.activity.confidence,
extras: location.extras,
});
});