-2

I started using Firebase in my app, and I already have login and signUp with email and password set up. How can I persist this user in my app to make secure authenticated requests and start using Firebase's cloud storage?

I noticed that after the login(or signUp) The user gets an uid. Can this uid be stored in localStorage and be used to make authenticated requests?

I also wanted to ask something related to firebase's possibilities on databases. I'm aware of the existence of cloud firestore and realtime database. The app that I'm building is a simple photoBook where users that are authenticated can create albums, and in this albums they can upload photos. My question is: I have to use Cloud Storage to make the file uploads and the realtime database to handle users and their albums?

gabriel_tiso
  • 1,007
  • 3
  • 11
  • 27
  • Asking for the best way is kinda opinion based. It might be better to instead ask if a specific way works for a specific reason instead of asking what is best way as that could result in opinionated answers. Might I also point out opinionated answers/questions are a big no-no on SO – The Grand J Sep 29 '20 at 00:11
  • I understand your point, but my main doubt is about the fact that I should or not store an uid in localStorage(or cookies too) to make authenticated requests]] – gabriel_tiso Sep 29 '20 at 00:17

1 Answers1

1

If all you need to do is get the UID or ID token of the authenticated user for future use, there's no need to persist anything. Firebase Auth automatically persists a token for the user (in local storage), and refreshes it periodically. You don't have to do anything to make that happen.

When you should do is simply observe the auth state of the user to find out when the SDK has verified their account. Or if you need an auth token for calling a backend, there is another observer for that.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441