Firebase UID output to document with typescript cloud function

10 views
Skip to first unread message

Nathan Jones

unread,
Dec 16, 2020, 4:46:01 PM12/16/20
to Flutter Development (flutter-dev)
Hello, I'm new to both programming and Flutter but I'm starting to get my head around it. I am trying to put together an app that combines user and location information via Firebase so that I can show multiple user locations on a map. What I need help with and would like to do is write the Firebase UID and user location to the same Firestore document via a Typescript cloud function.

I've been working with this Firebase background location plugin for several months and have figured out a lot about how it works. Concurrently I've been trying multiple Firebase Auth templates and have learned a fair amount about what API options are available. Most importantly I understand that the UID is the key value to identify my users.

I've also learned a fair amount about Firebase cloud functions and how to write specific data to a Firestore collection. I've learned how to write the user information and UID to a collection with a Javascript cloud function and I've also learned how to write the location information (lat, lng, etc...) to a collection via a Typescript cloud function.

My working Typescript is below, it has the location data I need. Can I modify the Typescript to include information such as UID or perhaps email address sourced from user data stored in Firebase?  Thanks for reading and for any suggestions on how to proceed. 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,
    });
});

Suzuki Tomohiro

unread,
Dec 16, 2020, 5:47:10 PM12/16/20
to Flutter Development (flutter-dev)
I’m afraid that I didn’t get the challenge. I don't know what you know. (Do you need to know the meaning of TypeScript syntax? Flutter? Any error messages?)

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/f6a83c87-d43b-4486-88dd-ea24da422bfcn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages