I have created an ionic app,which stores data which is specific to a user in firebase database ,now I want to share this data to another users account,with the email provided ,so that when he retrieves his firebase data,the data which I have shared is visible too…
for example if i have login in my account and stored name of five books and authors in firebase database.Now I want to share the names of 2 books and authors to another account ,by knowing their email address,i.e if now that users logs in and retrieves his list,the books and authors which I have shared is visible too on retrieval of items…
If this is my database structure,Anw!EMoih… and HvzQET6qBcR… are the Uid for the respective users…
Kq6v8w3aa2… and Kq6vNjd2sb… are different keys storing my data…
now I want this key should be copied to HvzQET6qBcR…,i.e for this user if I know this email…
Since the user uid is different for different users email…
Then when querying, I can see which lists each user has access to and fetch those. And depending on the use-case, especially if there’s not that much data changing I would copy the entire list under the userProfile node, that way only one fetch brings me all the data I need, remember, text is cheap in the DB.
It would be best done server.side (or using Cloud Functions) so you can use the Firebase ADMIN SDK, there’s a method called getUserByEmail() that would do the trick.
so how should i store the id of shared list under that user profile…
Anw1EMoihGQkvUA4dJL9dsv1hZr1,
HvzQET6qBcRIs4s1n18oiHxxT8n2
are corresponding to a user profile…
how should I stored my shared files id say,Kq96RWxCAY8lA2hpNz8,if i want to share this data under this userprofile.,HvzQET6qBcRIs4s1n18oiHxxT8n2.,
please help me on this part…
Like I said, do you have a user profile node where you store the user’s information in the database? You can just pass it to that node, all you need is the ID, so you can have the profile be like this:
ok…
so here is my users node with data stored corresponding to every user,now how can i sharefiles id to any user here,
basically how can i put the shared id:true here…
HvzQET6qBcRIs4s1n18oiHxxT8n2,oyW7rInaXfaw7fmTdaTgjtIOfn23 are corresponding users…with -KqDwsgOC_w7UDBKMEZs,etc as their data stored…
I am now able to add the shared file to a user id(for now I am adding it to my own user id,since I am not knowing the user id of another person).
I first moved the data to the shared files folder,and now I am just pushing to my user id,so its now visible to me,but here I can see same data aa with different key name…
Is it right?
I am facing issue in getting user uid from email… using this function getuserbyEmail(),
I installed the firebase admin…
.from npm install firebase-admin
I also downloaded the file service-accounts.json…from firebase account…
getuid()
{
admin.auth().getUserByEmail('vgvithikagupta1@gmail.com')
.then(function(userRecord) {
// See the UserRecord reference doc for the contents of userRecord.
console.log("Successfully fetched user data:", userRecord.toJSON());
})
.catch(function(error) {
console.log("Error fetching user data:", error);
});
}
Then I imported it …
import * as admin from 'firebase-admin';
var serviceAccount = "../pages/serviceaccount.json";
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://nimble-valve-148606.firebaseio.com"
});
but when I was running this ,I am getting error.
cannot find module Cannot find module ‘jsonwebtoken’. in Credential.js file inside firebase admin…
Sorry, I wasn’t clear enough, the admin SDK only works server side, so you’d need to handle that part through Firebase Cloud functions or creating a small server somewhere to do it.