firebase getAuth(), a getAuth(app) z parametrem

firebase getAuth(), a getAuth(app) z parametrem
Krwawy Ork
  • Rejestracja: dni
  • Ostatnio: dni
  • Postów: 105
0

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?

Kopiuj
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);
Kopiuj
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:

Kopiuj
/**
* 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;
Xarviel
  • Rejestracja: dni
  • Ostatnio: dni
  • Postów: 847
0
Krwawy Ork napisał(a):

zastanawiam się jaka jest różnica... czy faktycznie getAuth potrzebuje jako parametr obiekt?
export declare function getAuth(app?: FirebaseApp): Auth;

Nigdy nie korzystałem z firebase'a, ale taki zapis parametru app?: FirebaseApp w TypeScripcie oznacza, że nie jest on wymagany.

Zarejestruj się i dołącz do największej społeczności programistów w Polsce.

Otrzymaj wsparcie, dziel się wiedzą i rozwijaj swoje umiejętności z najlepszymi.