I’m trying to set the persistence to ‘Session’ using typescript/react, but getting type errors.
Here is some of code:
import { auth } from "../auth/firebase";
import {
createUserWithEmailAndPassword,
sendPasswordResetEmail,
setPersistence,
signInWithCustomToken,
signInWithEmailAndPassword,
updateProfile,
} from "firebase/auth";
This is my useEffect:
useEffect(() => {
console.log("here useEffect");
auth.setPersistence(auth.Auth.SESSION.NONE); //Property 'Auth' does not exist on type 'Auth'.
const unsubscribe = auth.onAuthStateChanged((user: any) => //this works fine
I tried a different solution I found here, that looked like this:
setPersistence(auth, {type: 'LOCAL'});
This didn’t work either.
2
Answers
See the documentation for an example.
Also see the API documentation for setPersistence.
This table expands on the documentation Supported types of Auth state persistence. The TypeScript constants (TS const) are new values used with the modular API (in lieu of the old enum values used in the namespaced API).
firebase.auth.Auth.Persistence.LOCAL
browserLocalPersistence
firebase.auth.Auth.Persistence.SESSION
browserSessionPersistence
firebase.auth.Auth.Persistence.NONE
inMemoryPersistence
Example using Web modular API
Same example using Web namespaced API