I'm learning Firebase. In many code examples I see something like this:
const auth = getAuth();
await signInWithPopup(auth, provider);
while in firebase web codelab they call getAuth directly:
await signInWithPopup(getAuth(), provider);
same thing with getFirestore.
so which one is the correct way of doing it and if they are both the same what is the better practice?
edit: when I need to use auth object more than once will I get any performance benefits by calling getAuth once and assigning it to a variable?
These two code examples are functionally the same. The first example is simply more verbose.
If you don't need to reuse the auth variable, then you can simply call it directly.
It doesn't have any significant difference in this case.
There's no difference between those two approaches. If you want to use the result that is returned by getAuth(), only once, it makes sense to use it like this:
await signInWithPopup(getAuth(), provider);
Otherwise, save it to the auth variable and use it as many times as you want. In terms of performance, there is no difference at all.