Is it possible for my app Web to create a "faketoken" and use it to register with Backend and receives some information - hidden and without user confirmation?
What I need is to inform the browser, with information on screen that another user changed the object, so FrontEnd has to reload the data or block the Save action while the current user does not get the latest version of the object.
I just need to inform the Front End of this change and it resolves what to do.
Is not a push notification.
I don't know if firebase can do that or if I need to implement something like socket.io.
Thanks
Related
I made a page where users can update their names and status just like WhatsApp & Telegram.
These changes are published using LAZY mode since I don't want to update every user using the app right away. I just want to fetch it manually when necessary (for example when the user open the chat view with that user). (https://mesibo.com/documentation/api/real-time-api/profiles/#profile-publishing-mode)
The problem is: how can I fetch the updated profile of other users?
Whenever I get the profiles with Mesibo.getProfile("address") the data is still not updated.
since I don't want to update every user using the app right away.
Even if you use real-time mode, updates don't go to every user but only those users who have subscribed to it.
https://mesibo.com/documentation/api/real-time-api/profiles/#subscribing-to-a-profile
In lazy mode, it may be updated along with other profiles or when the message is received from the users. Before that, getProfile may not return the latest profile.
If you are starting with mesibo, recommend using real-time mode and optimizing later using the lazy mode
I have a cloud function that creates my custom user object in the data base once a new user has registered.
Meanwhile in the app itself, after a user is registered, they are transferred to the main page.
The problem is, that the first executed function in the main page (crucial) is getting the user object, because it is needed for any action in the app.
But because the page opened before the cloud function has created this user object, when the function in the main page tries to get that object it doesn't exist yet.
The result of that is that as soon as the user clicks anything pretty much, they are sent back to the register page.
The register activity recognizes that they are actually logged in, send them back to the main page, and at that point everything would work as the object has been created, but the experience for the user isn't great and it feels like an error.
How can I prevent that? What's the simplest thing I can implement in my register activity, that would wait for some signal from the cloud function that the object has been created, before sending the user to the main page?
You can instruct your app to listen on the document that it expects to be created, using a DocumentReference onSnapshot or whatever is the equivalent for your client platform. The obvious requirement is that your app knows the exact path of the document that the function is going to create. In your case, it sounds like the client can know based on the user's UID assigned by Firebase Authentication.
If your app can't identify that document that's expected to be created by the function, then the function is going to have to tell the client. If it's an HTTP type function, the client should receive this document ID in the response. If it's not an HTTP type function, then you'll need to find yet another way to inform the client of what it's waiting on.
In any event, the onSnapshot callback will be triggered when the document is created, and you can use that to determine when to allow the user to proceed. You should of course remove the listener from that DocumentReference when you're done.
(this was originally a post on the flutter-dev reddit that was redirected here)
So I started making this flutter app using firebase as a backend and after looking at all the options for state management I finally realised that the tools provided by firebase already handle pretty much everything I would need state management for.
For example:
I could set the currently logged in user in my state to show the right login or home page and make the user uid available to widgets for their firestore API calls.
OR
I can just listen to FirebaseAuth.instance.onAuthStateChanged to show the right page and just use FirebaseAuth.instance.currentUser() from anywhere to get the logged in user uid and do my firestore calls.
What I mean is, for every thing that would require global state, I can just basically have a firebase stream listener.
Is this right ? Or am I missing something here ?
You're not missing anything. Since most Firebase APIs rely on data from Google's servers, many of them are designed to be used in a reactive way. Making your UI reactively respond to those asynchronous changes is (in my experience) the best way to keep your code simple.
There may be slight behavior between the different types of listeners. But the onAuthStateChanged listener immediately fires with the current state when you attach it, which makes it a good example of a listener that you can use everywhere you need to respond to auth state (instead of also storing that state somewhere in your app).
In that scenario I would say yes, you can read the onAuthStateChanged stream and react to changes. But there are also scenarios where I need a stream for interacting between widgets without a parent/child relationship. For example, in one of my apps I have a company selector, and the rest of the app reflects to the selected company. I created a stream, so that the company selector doesn't need to be a parent of the other widgets, and especially so that I don't need to pass the company parameter to all the widget tree.
I also have one scenario where I need to load extra information about the user that isn't available on the FirebaseUser object. So when the user is logged on I load their information from a "users" collection and then I add that to a custom stream.
So to conclude I would say yes, you should use the default Firebase streams when possible, but that doesn't mean you can or should use that solution for everything.
Is there a way to know if a newly created user was done so using the client or admin SDK?
No, the auth trigger isn't origin specific. It doesn't care how a new user account gets created... it doesn't get called/triggered until the creation occurs.
Not to go too far off topic from your question, or turn this into a fully-fledged conversation, but what are you trying to accomplish that you want to detect what created the account? I feel like there's probably a different way to handle the scenario you're facing.
I am trying to fix the question I post firestore rules request.auth.token.firebase.identities["phone"] not update on IOS
Currently fix by call firebaseUser.getIdToken(refresh: true); to make refresh update after phone verified and app started.
Would call firebaseUser.getIdToken(refresh: true); every app start be a problem? I think maybe if bunch of users keep fetching ID Token with server will causing server overload or something?
While I don't think it would be a problem, it's not really the best way to go about getting the most recent ID token. If you just want to know the most recently fetched ID token, you can use addIDTokenDidChangeListener() to receive any updates to the ID token whenever the Firebase SDK automatically refreshes it (every hour).
You typically only force a refresh token if you know the custom claims or other information in the ID token have changed on the server, and you need to reload those for use on the client. If this is not your situation, you probably don't need to force a reload.