How to get user's list in firebase auth - javascript

I am working on the vue-firebase application and want to know that how can I get the list of all registered users in firebase auth.

I am quite not sure if that is possible with one user try to get all the users, unless you are using firebase-admin. Though I have an idea how you can do that if you trying to get a list of added user being another user.
So, try to keep another list when a new user logs in, add the user details to a new node like userList.
And when ever you need them, call that node.
And incase you are using firebase-admin
admin.auth().listUsers(1000, nextPageToken)
.then(function(listUsersResult) {
will give the list.
Here's a reference. https://firebase.google.com/docs/auth/admin/manage-users#list_all_users

Related

How to login a user using firebase authentication

I'm currently using firebase-admin to create a web Dashboard with node.js as a backend which will have multiple users and those users have user specific data in my database, note that I need them to be able to delete or add stuff to the database as well, I've managed to add new users to Autentication using firebase.auth().createUser() programmatically, but how would one go about logging in a user, and then from there controlling which uid is logged in and displaying his data (giving him access to the correct data, obviously don't want him messing with someone elses data).
I know this might seem like a really newbie question, and it probably is, but firebase docs always get me confused for some reason. Any tips? I'd greatly appreciate.
Any questions don't hesitate.
To login a new user, try this:
firebase.auth().signInWithEmailAndPassword(email, password)
this returns a Firebase.Promise which you can use to track the operation progress. If successful, it will return the corresponding Firebase.User object.
From there, the logged-in user will also be available in the firebase.auth().currentUser property. You can then use the user's uid property as a key for his JSON branch on the database.

Creating a Favorites list with shareable url using node an mongoDB

I've been searching a ton and maybe I'm using the wrong search terms, but essentially I want to have a user select items to add to a favorites list and then create a unique url they can share. An example can be found at http://www.sortfolio.com
When you click the "shortlist?" button at the bottom of an item it'll get added to the "My Shortlist (Your Favorites)" and when you click there it'll show what you've added to your favorites list and provide a shareable unique url with your favorites.
I have a MongoDB database and using Node with Express. I'm assuming you'd collect the items database id's and then make a get call to grab them, but how would I then create the unique shareable url. I think sortfolio is built with Ruby on Rails which I am not using. If anyone can point me in the right direction to replicate this type of functionality it would be a great help.
Hi just like you said you've to create one another Mongodb collection like favorites
{
favouriteid:unique id/if you want short uid the u can us npm uid,
Item:ref to production product collection
}
Then create an api for getting favorites according to favorites.
And in given site example user can shortlist and share item without login also. So in this case on Frontend side store shortlist in product in sessionstorage and if user want to see favorite list then add new favorite record with items fetching from sessionstorage or locals to rage. Provide sharable url which have unique sharable I'd. Above thing manage according to cookie basic.

How to Share session between different clients accessing a Meteor website? Collaborative ToDos?

I am learning web development and lately Meteor has caught my fancy.
I went through the starter tutorial of creating to-dos and use save button to commit the list to database. It allows everybody who opens the website to see the same to-dos list.
I added user log in system in to-dos so that people can login and see only their own to-do list.
Now, I'm trying to extend above example, for Collaborative to-dos.
Here is a sample use case:
My boss logs-in at do.com and starts creating his to-do list. While the Boss is logged in, I also happen to open do.com from my laptop and I see a message flashing - A session is already open. Do you want to collaborate with Boss? If I say 'Yes', Boss will be notified at his screen to allow me access to his list, and on granting access, I will be able to collaborate with Boss's to-do with both of our changes in the list reflecting on each other's screen but the final save/commit button remains frozen for me (because I came later) and remains active only for Boss. So, when Boss hits the save button, the list is committed to database with his and my changes.
If Boss chooses to not allow me to contribute, I get to see my own to-do.
On the other hand, if I choose NO, I get a fresh start at my to-do list with no bearing on already open sessions elsewhere.
The scenario should work other way round too. If I am the one who has an active session at do.com and Boss happens to open his own later, he should get the message whether he wants to collaborate with me and so on.
What would be the best way to implement this in Meteor? I came across this Persistent Session package which could be the solution but I am not able to adapt it to my use-case of allowing/denying another user via message/notification. Appreciate, any help on this. I'm a complete newbie here, pls excuse of any un-necessary verbiage, I wanted to explain my question well.
Thanks in advance.
Session is not the right tool for this, you want to use the server db (Collections) to mediate this collaboration.
Given that you created todo lists specific to users, I'm going to assume you have a publication somewhat like this:
Tasks = new Mongo.Collection("tasks");
if (Meteor.isServer) {
Meteor.publish("tasks", function () {
return Tasks.find({owner: this.userId});
});
}
So the next step is to change this so you can see your own tasks, and also those belonging to any user who shares their tasks with you. This could be created like this:
Tasks = new Mongo.Collection('tasks');
CanView = new Mongo.Collection('canView');
// CanView holds docs with this schema:
// {
// user: 'DzxiSdNxEhiHMaoi6',
// taskLists: ['DzxiSdNxEhiHMaoi6', '7X97ZhPxjX6J4eNWx']
// }
if (Meteor.isServer) {
Meteor.publish('tasks', function () {
var canView = CanView.findOne({user: this.userId}).taskLists;
return Tasks.find({owner: {$in: canView}});
});
}
On the client tasks could be displayed as one single list, or segregated by the owner property.
How you add and remove ids into the CanViews tasklist list will depend on the workflow for requesting access/offering to share, etc.
The other part of the workflow you mentioned is only the Boss being able to save the changes, but still have them reactively update on both screens. This would take more work as you would need to implement a 2 step process, with two collections on the server. i.e. Boss's (task owner's) saves are committed directly to the canonical Tasks collection, and other users saves to a second TaskUpdates Collection. Both published to the clients, which then have to overlay the data from TaskUpdates over the actual Tasks in a way that is clear and meaningful.

Checking if a "distinct_id" already exists in Mixpanel Javascript

Is there a way to check to see if a previous "distinct_id" already exists in Mixpanel with Javascript?
I am currently having an issue where once someone moves through my onboarding process and all the events are tracked, if they log out and log back in it is creating a separate record in the "explore" section of the admin interface.
I want to be able to throw some logic around my initial login event to make sure to check if the "Distinct_id" already has been used, and then tie the login event to that same user instead of creating a brand new one in Mixpanel.
It would be great to see your code, but I can guess the following answer based on my experience:
The first time you create a people profile, you should create it executing mixpanel.alias(YOUR_DISTINCT_ID) instead of mixpanel.identify(). This will associate the mixpanel internal distinct_id with your custom distinct id (for instance: an email address, an username, etc).
Next time the user lands on a different page, you call mixpanel.identify(YOUR_DISTINCT_ID).
Doing so, if the user logs out, and then logs in back, calling mixpanel.identify(YOUR_DISTINCT_ID) will be enough, Mixpanel is going to associate your custom id with the original one avoiding duplicated profiles.

Parse master key cloud code following users

I'm building a simple social network app for iOS with parse and I'm currently working on the relationships, such as follower and following. I have follower and following column in my data browser saved as an array so I can save all the usernames. So this is what I'm having trouble with: Say the current user is viewing a user's profile and clicks follow I need to have the current user's name save in the follower array of the user he/she is viewing. Now as far as I know I can't o this on the client side, and it isn't a good idea anyway for security reasons to do ether. So I want to try to use the Master Key and cloud code to add each of the user's names to their appropriate array. I have never used cloud code before and I want to make sure that this is the best way to do this. I set up the Cloud Code I just don't know where to begin. Any suggestions would be appreciated!
I would start by creating a new function in main.js in your cloud code folder. Just insert the Parse.Cloud.useMasterKey(); part at the beginning. I would send up the object id of the user you are modifying, then in the function grab the array from that user, and add the current user to it. Then save and send back a success variable.
To call this from Xcode you would have something like this:
[PFCloud callFunctionInBackground:#"editFollowers" withParameters:#{#"user": Put objectId for user here}
block:^(NSString *response, NSError *error) {
if (!error) {
}
}];

Categories