witam!
mam pytanie, które dotyczy firebase ale w wersji Web version 9 (modular)
Poniżej zacytowałem dwa kawałki kodu z dokumentacji i mamy tam:
const auth = getAuth(); i const auth = getAuth(app);
zastanawiam się jaka jest różnica... czy faktycznie getAuth potrzebuje jako parametr obiekt?
import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
// TODO: Replace the following with your app's Firebase project configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
const firebaseConfig = {
// ...
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
// Initialize Firebase Authentication and get a reference to the service
const auth = getAuth(app);
import { getAuth, createUserWithEmailAndPassword } from "firebase/auth";
const auth = getAuth();
createUserWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
// ...
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
// ..
});
edit:
fragment komentarza ten funkcji:
/**
* Returns the Auth instance associated with the provided {@link @firebase/app#FirebaseApp}.
* If no instance exists, initializes an Auth instance with platform-specific default dependencies.
*
* @param app - The Firebase App.
*
* @public
*/
export declare function getAuth(app?: FirebaseApp): Auth;