I cannot get my google firebase auth to work, I get the following error Cannot find name 'Persistence'. Did you mean 'setPersistence'?ts(2552)
Here is my code. I tried to import it but still gets an error. This is in TypeScript where do I import from? It appears UserCredential and Persistence are both an interface.
import { initializeApp, FirebaseApp, FirebaseError } from 'firebase/app';
import {getAuth, GoogleAuthProvider, Auth, signInWithPopup, UserCredential, setPersistence } from "firebase/auth";
export interface IUser {
displayName: string | null;
email: string | null;
providerId: string;
uid: string;
}
const firebaseConfig = {
apiKey: "apiKey",
authDomain: "authDomain",
databaseURL: "databaseURL",
projectId: "projectId",
storageBucket: "storeageBucket",
messagingSenderId: "messageSenderId",
appId: "appId",
measurementId: "measurmentId"
};
const _getApp = (): FirebaseApp => {
const app = initializeApp(firebaseConfig, 'MyExample');
return app;
}
const _setPeristence = async (): Promise<void> => {
const app = _getApp();
const auth = getAuth(app);
setPersistence(auth, Persistence.LOCAL);
return Promise.resolve();
}
const _signInWithProvider = async (resolve:any): Promise<void> =>{
const currentUser = await GetGoogleUser()
if (currentUser != null) {
return resolve();
}
else {
const provider = new GoogleAuthProvider();
provider.addScope('profile');
provider.addScope('email');
const auth = getAuth(_getApp());
signInWithPopup(auth, provider)
.then((result: UserCredential) => {
}).catch((error: FirebaseError) => {
});
}
}
const SignIn = async (resolve: any): Promise<void> => {
await _setPeristence();
_signInWithProvider(resolve);
return;
}
export {
SignIn,
}