I have a NodeJS backend and an Ionic front-end. I use Firebase authentication to sign users in. When sign in succeeds, I want to get a JWT token to talk with my Node backend.
JWT tokens can be generated by my backend: when a user signs in on the client app, I perform a call to the node backend, which returns a JWT token, and can continue talking with the backend using JWT. This approach requires that my backend be aware of the users that signed in to Firebase, otherwise it can't tell whether the user requesting a token is valid.
Solving the above problem is possible with cloud functions I think: when a user is created, I perform a call from Firebase to my backend to say "Hey, user with uid
myUid
has just signed up. When client apps get the JWT token from the backend, it will look for their uid
in registered uid
s list.
I don't like this approach because I have to keep a record of users in my backend, plus Firebase calls to my backend are asynchronous, so a user could try to get a JWT token before its uid
has been registered.
Another option is to write a cloud function that generated a JWT. This way, no async problems, and the call can be performed right after sign-in. But I'm not sure this is even possible.
How would you solve this use case ?
via user5365075