firebase/snippets-web

wrong code

Opened this issue · 0 comments

Github documentation page:

// These samples are intended for Web so this import would normally be
// done in HTML however using modules here is more convenient for
// ensuring sample correctness offline.
import firebase from "firebase/app";
import "firebase/auth";
function setPersistenceSession() {
var email = "...";
var password = "...";
// [START auth_set_persistence_session]
firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION)
.then(() => {
// Existing and future Auth states are now persisted in the current
// session only. Closing the window would clear any existing state even
// if a user forgets to sign out.
// ...
// New sign-in will be persisted with session persistence.
return firebase.auth().signInWithEmailAndPassword(email, password);
})
.catch((error) => {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
});
// [END auth_set_persistence_session]
}

Firebase documentation page:

https://firebase.google.com/docs/auth/web/auth-state-persistence?hl=pt-br#web_1

wrong imports: ❌

import firebase from "firebase/app";
import "firebase/auth";

correctly imports: ✅

import firebase from "firebase/compat/app"; // Or the modular import
import "firebase/compat/auth"; // Or the modular import for getAuth