I am getting the below error even though i have all permissions. This is a custom action where in i am trying to get the document reference of a existing firebase document in 'users' collection & trying to create a new firebase document in 'subscriptions' collection with the same document reference
Error creating subscriber document: FirebaseError: [code=permission-denied]: Missing or insufficient permissions.
How do i go about fixing this error?
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
import 'package:cloud_firestore/cloud_firestore.dart';
// import 'package:flutter_flow/flutter_flow_firestore.dart';
// Set your action name, define your arguments and return parameter,
// and then add the boilerplate code using the green button on the right!
Future createSubscriberDocwithSameDocRefAsUsers(
String? stripecustomerid,
String? uid,
String newdoccollectionname,
) async {
try {
// Add your function code here!
// Add a new document in collection "cities" with ID 'LA'
// const res = await db.collection('cities').doc('LA').set(data);
// Get the document reference for the users document
// final usersDocRef = getFirestore().collection('users').doc(uid);
final usersDocRef = FirebaseFirestore.instance.collection('users').doc(uid);
// Create a new document in the subscribers collection with the same document reference
final subscribersDocRef =
usersDocRef.collection(newdoccollectionname).doc();
// Set the stripe customer ID on the subscribers document
await subscribersDocRef.set({
'stripeCustomerId': stripecustomerid,
});
print('Subscriber document created successfully.');
} catch (e) {
print('Error creating subscriber document: $e');
}
}