I'm using Firebase Authentication. Should I have one auth = getAuth() in the root App component and pass that around via Context, or can I just call auth = getAuth() in every file that needs it? I'm using the second approach right now because it's simpler, and it seems to work; the idToken that's returned is the same across different files/pages.
More questions:
- Does getAuth() have to be in a component, or can it be outside? Does it have to be in a useEffect so it’s only called once?
- Why is auth.currentUser.accessToken marked by TypeScript as not existing? But when I console.log currentUser, the accessToken key is there. I can ignore TypeScript’s error and just use currentUser.accessToken and it works. It’s more convenient than using .getIdToken(), which I have to await.