I am new to firebase and I need some help with something.
I am creating an application which allows users to post tasks. When a user saves a task their uid is sent to the database along with the task information. In my database I have a separate child for users which contains all of a users information, i.e name and other stuff.
When my app starts I want to pull all tasks from firebase and according to the uid saved with a task, I want to pull the user information corresponding to that task so that I could set correction information on the cards.
I need help achieving this, thanks.
Related
I am developing a website in HTML, JS, and CSS. My result is a PWA (Progressive Web App). It works really great. I am hosting and serving it via the Firebase Hosting and enjoy many functions of firebase. To let the user feel the full power of a PWA I need to manage Push Notifications. For that, I want to use Firebase Cloud Messaging. I already know how to send push notifications and so on. On my webpage, the users can subscribe to topics. And here we go. I do not know how to subscribe/unsubscribe a user to a topic via the javascript without the admins SDK. Can please provide somebody a clear and simple example for subscribe/unsubscribe users? From the documentation, I will not be smart.
Thanks in advance,
Filip.
I would do it like that:
(I assume you have users tokens stored somwhere in the database ordered by users id)
Create table 'topics' - store users ids there.
Create form - let the user add its id to the 'topic' table.
Then, before sending FCM, store every token, from owners which ids are assigned to the specific topic in the 'topic' table.
I am trying to have a one to one chat feature using firebase. Right now, my structure of messages makes sense in the fb database but I am not able to implement one to one chat feature using firebase's api in angular. I am able to spam a chat room where all the users can see everyone's messages but i would like to have a one to one chat feature in my application. My structure is good in the firebase database and i just need to manipulate my javascript code to make it work. My code is as follows.
function chatController($scope,$firebaseArray) {
var ref1=firebase.database().ref().child('users/59c1c11cec/chats/-KuRshPYbO_d9B');
$scope.chats=$firebaseArray(ref1);
var ref=firebase.database().ref().child('chats/-KuRshPYbO_d9B/messages');
$scope.messages=$firebaseArray(ref);
$scope.send=function(){
$scope.messages.$add({
message:$scope.messageText,
// date:Date.now()
})
}
}
I am able to create a one to one chat between two users by hard coding their user ids, but I was wondering if firebase's api is able to do this dynamically. If yes, how would I do it? For reference, 59c1c11cec is the current logged in user id, -KuRshPYbO_d9B is the other person's id who the current person is starting a conversation with which I don't have any access to in my own database but only in firebase's database. And using that users id I retrieve the messages between the two users. How will I be able to achieve this? I just need to replace the hard coded values with the values I talked about.Thanks a lot in advance!
I implemented friendly chat. But that is group chat. I am new to firebase. Need docs for creating one to one web chat. How to get list of user accounts and selecting single user to send message? Please help me
If the users communicating have user IDs uid_1 and uid_2.
The database structure should be:
contacts
--uid1
--uid2
--uid3
-- so on (1)
--uid2
--uid1
--uid4
-- so on (2)
messages
--uid1
--uid2
-- Push messages here.(3)
--uid2
--uid3
-- Push messages here also.(4)
Adding Contacts
If USER 1 knows USER 2 you can add USER 2 in location (1) and add USER 1 in location (2). Since you are implementing with user IDs the USERS will be able to send messages if they know the other USER's uid. You can send Chat Invites to exchange uids.
Adding Messages
If USER 1 or USER 2 sends a message add at locations (3) and (4). This implementation will make sure that even if USER 1 deletes a conversation with USER 2, USER 2 will still have a copy and thus ensuring privacy.
These are the key elements to make a basic one-on-one Firebase Chat App.
NOTE: User IDs are provided by Firebase on successful authentication.
Maybe try breaking your problem into individual milestones and learn how Firebase works as you need help in each milestone.
According to what you have written, you have to:
Authenticate Users (https://firebase.google.com/docs/auth/)
Save those user profiles onto the Real-Time Firebase Database in the following data structure (https://firebase.google.com/docs/database/)
List those users in a List / RecycleView (learnhowtoprogram.com/android/data-persistence/firebase-recycleradapter)
Manage the conversation through listeners in the adapter that reference child nodes which serve as rooms between 2 people.
Think about how to make your structure as efficient as possible such as not saving conversations twice under each user but rather saving a reference to a separate 'conversations' node.
I recently implemented this in my location-based app (Occupapp) if you want a live example. You will have to register, add a service and log in from another device and select that service to chat to the owner.
i have a project i am working on
the requirements are to build a service to manage customers
the service has the following functionaltiy
Create Customer
Find Customer by Id
Update Customer
Delete Customer
each customer has and id, Name, Email, Address and related credit card tokens
When Customer is created it can be linked to one or more credit cards
and when updating a customer it can be linked to a credit card
The Credit Cards are managed in a different service (one that is not built by me) that i know nothing about (can make some assumptions)
The service i built is a web api project with an sql server database
i used asp.net entity data model for that and i implemented all of the CRUD operations using the rest api
my question is how can i create the link between the 2 services to allow me to link a credit card from a different service to my customer.
the requirments are that if some one wants to view the data of the credit cards it will need to use the other service so i dont need to have access to the credit card data, only to allow to link a credit card to a customer
any ideas on how this can be done?
Unfortunately your question is a little ambiguous and, after reading your comments, it seems your question is essentially asking how to "link" to a different service, which does not exist. If you don't know anything about the other service (and certainly if it does not exist), it will be very difficult to help you "link" to it.
You mentioned that the other service may be developed. In that case, I can suggest the following:
Connect to the underlying database that the external information is being stored in, much as you are connecting to your own database now (see connecting to databases in mvc for more information)
If you are not granted access to the external database, you will most likely utilize some form of web service to make queries against the external database (see consuming web services in mvc).
From your backend, the logic basically goes: access their database or call their web service, get the id for the credit card and either pass that id through or generate your own (internal) unique id for a credit card (and creata a separate table that stores the original id as well) and associate that with your customer (in an array or object, etc). That way, when you need to retrieve credit card information, you have your customer entry with the information (id(s)) of any associated credit cards. You can use that information to query from the external service to get the required credit cards and then combine the information
I'm already familiar that MongoDB is based on documents that are in JSON format. I'm creating my first web app using the MEAN stack, where users can register and then be able to sign in to a back-end dashboard where they can implement products/profile information etc. How would I set that up to be stored on MongoDB? would each user be stored as a document? And as far as security reasons, how can I go about not allowing a GET request to be able to get a different users information?
Currently, I just have a collection of users, and a collection of products (with the unique id number for each user), etc. to me that doesn't seem the proper way to store data.
If anyone can help me on how to setup the database for Mongo that would be fantastic! Thanks in advance!
would each user be stored as a document?
Yes, each user is an object, thus it's stored as a separate document.
how can I go about not allowing a GET request to be able to get a different users information?
This has nothing to do with Mongo or any other data storage mechanism. You'll need to work on a Web service layer which exposes your data filtering requests to authorize them based on user role, claims or any authorization approach you might find useful in your scenario.
Maybe you should look at implementing OAuth2. There's a package that integrates with Express to implement your own OAuth2 authorization server: node-oauth2-server.
Currently, I just have a collection of users, and a collection of
products (with the unique id number for each user), etc. to me that
doesn't seem the proper way to store data.
You are on the right way actually. Now when you show products page for users you need to retrieve only documents that belong to that single user that is currently authenticated, this implies that you have authentication set up, and products have a userId field.
This is how most application work. If you want to read about other ways of solving this then read about multi-tenancy.