Property 'auth' does not exist on type 'AngularFireAuth'.
error TS2339: Property 'auth' does not exist on type 'AngularFireAuth'.
just delete 'auth' like 'this.afAuth.signInWithEmailAndPassword(email, password)' and it will be work
GoogleAuth() { return this.AuthLogin(new auth.GoogleAuthProvider()); } how can i remove auth here if removed its unable to find .GoogleAuthProvider() please help me out here
yeah! it got resolved by replacing firebase.auth
@YassineBaggar I have deleted auth it's working but still isn't working with send email verification otherwise it's working fine. Can you help me with this ?
Can you tell me the issue in detail so that I may try to help you out
On Thu, 17 Dec 2020, 6:43 am KrutarthChovatiya, [email protected] wrote:
@YassineBaggar https://github.com/YassineBaggar I have deleted auth it's working but still isn't working with send email verification otherwise it's working fine. Can you help me with this ?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/SinghDigamber/angularfirebase-authentication/issues/8#issuecomment-747140005, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANMXB4VFIHWDCT4V74NTC63SVFLKTANCNFSM4MKU4ICA .
@IMSRIJAN04 I have removed auth from signing signup also used firebase.auth.GoogleAuthProvider() and it all worked but removing auth from sendemailverification isn't working
Please use import firebase from 'firebase'; and in service // Sign in with Google GoogleAuth() {
return this.AuthLogin(new firebase.auth.GoogleAuthProvider());
} FacebookAuth() {
return this.AuthLogin(new firebase.auth.FacebookAuthProvider());
}
Hi, I have solved this bug based on another repository.
First step: Open auth.service.ts and remove the line
//import { auth } from 'firebase/app';
Second step: import firebase
import firebase from 'firebase';
Third step: Update the following lines
Old way:
SignIn(email, password) {
return this.afAuth.auth.signInWithEmailAndPassword(email, password)
.then((result) => {
this.ngZone.run(() => {
this.router.navigate(['dashboard']);
});
this.SetUserData(result.user);
}).catch((error) => {
window.alert(error.message)
})
}
New way:
SignIn(email, password) {
return this.afAuth.signInWithEmailAndPassword(email, password) //Only remove auth
.then((result) => {
this.ngZone.run(() => {
this.router.navigate(['dashboard']);
});
this.SetUserData(result.user);
}).catch((error) => {
window.alert(error.message)
})
}
Old way:
SignUp(email, password) {
return this.afAuth.auth.createUserWithEmailAndPassword(email, password)
.then((result) => {
/* Call the SendVerificaitonMail() function when new user sign
up and returns promise */
this.SendVerificationMail();
this.SetUserData(result.user);
}).catch((error) => {
window.alert(error.message)
})
}
New way:
SignUp(email, password) {
return this.afAuth.createUserWithEmailAndPassword(email, password) //Only remove auth
.then((result) => {
/* Call the SendVerificaitonMail() function when new user sign
up and returns promise */
this.SendVerificationMail();
this.SetUserData(result.user);
}).catch((error) => {
window.alert(error.message)
})
}
Old way:
SendVerificationMail() {
return this.afAuth.auth.currentUser.sendEmailVerification()
.then(() => {
this.router.navigate(['verify-email-address']);
})
}
New way:
//add async/await and remove auth
async SendVerificationMail() {
return await(await this.afAuth.currentUser).sendEmailVerification()
.then(() => {
this.router.navigate(['verify-email-address']);
})
}
Old way:
ForgotPassword(passwordResetEmail) {
return this.afAuth.auth.sendPasswordResetEmail(passwordResetEmail)
.then(() => {
window.alert('Password reset email sent, check your inbox.');
}).catch((error) => {
window.alert(error)
})
}
New way:
ForgotPassword(passwordResetEmail) {
return this.afAuth.sendPasswordResetEmail(passwordResetEmail)//remove auth
.then(() => {
window.alert('Password reset email sent, check your inbox.');
}).catch((error) => {
window.alert(error)
})
}
Old way:
GoogleAuth() {
return this.AuthLogin(new auth.GoogleAuthProvider());
}
New way:
GoogleAuth() {
return this.AuthLogin(new firebase.auth.GoogleAuthProvider()); //add firebase
}
The complete code:
import { Injectable, NgZone } from '@angular/core';
import { User } from "../services/user";
import firebase from 'firebase';
//import { auth } from 'firebase/app';
import { AngularFireAuth } from "@angular/fire/auth";
import { AngularFirestore, AngularFirestoreDocument } from '@angular/fire/firestore';
import { Router } from "@angular/router";
@Injectable({
providedIn: 'root'
})
export class AuthService {
userData: any; // Save logged in user data
constructor(
public afs: AngularFirestore, // Inject Firestore service
public afAuth: AngularFireAuth, // Inject Firebase auth service
public router: Router,
public ngZone: NgZone // NgZone service to remove outside scope warning
) {
/* Saving user data in localstorage when
logged in and setting up null when logged out */
this.afAuth.authState.subscribe(user => {
if (user) {
this.userData = user;
localStorage.setItem('user', JSON.stringify(this.userData));
JSON.parse(localStorage.getItem('user'));
} else {
localStorage.setItem('user', null);
JSON.parse(localStorage.getItem('user'));
}
})
}
// Sign in with email/password
SignIn(email, password) {
return this.afAuth.signInWithEmailAndPassword(email, password)
.then((result) => {
this.ngZone.run(() => {
this.router.navigate(['dashboard']);
});
this.SetUserData(result.user);
}).catch((error) => {
window.alert(error.message)
})
}
// Sign up with email/password
SignUp(email, password) {
return this.afAuth.createUserWithEmailAndPassword(email, password)
.then((result) => {
/* Call the SendVerificaitonMail() function when new user sign
up and returns promise */
this.SendVerificationMail();
this.SetUserData(result.user);
}).catch((error) => {
window.alert(error.message)
})
}
// Send email verfificaiton when new user sign up
async SendVerificationMail() {
return await(await this.afAuth.currentUser).sendEmailVerification()
.then(() => {
this.router.navigate(['verify-email-address']);
})
}
// Reset Forggot password
ForgotPassword(passwordResetEmail) {
return this.afAuth.sendPasswordResetEmail(passwordResetEmail)
.then(() => {
window.alert('Password reset email sent, check your inbox.');
}).catch((error) => {
window.alert(error)
})
}
// Returns true when user is looged in and email is verified
get isLoggedIn(): boolean {
const user = JSON.parse(localStorage.getItem('user'));
return (user !== null && user.emailVerified !== false) ? true : false;
}
// Sign in with Google
GoogleAuth() {
return this.AuthLogin(new firebase.auth.GoogleAuthProvider());
}
FacebookAuth(){
return this.AuthLogin(new firebase.auth.FacebookAuthProvider());
}
// Auth logic to run auth providers
AuthLogin(provider) {
return this.afAuth.signInWithPopup(provider)
.then((result) => {
this.ngZone.run(() => {
this.router.navigate(['dashboard']);
})
this.SetUserData(result.user);
}).catch((error) => {
window.alert(error)
})
}
/* Setting up user data when sign in with username/password,
sign up with username/password and sign in with social auth
provider in Firestore database using AngularFirestore + AngularFirestoreDocument service */
SetUserData(user) {
const userRef: AngularFirestoreDocument<any> = this.afs.doc(`users/${user.uid}`);
const userData: User = {
uid: user.uid,
email: user.email,
displayName: user.displayName,
photoURL: user.photoURL,
emailVerified: user.emailVerified
}
return userRef.set(userData, {
merge: true
})
}
// Sign out
SignOut() {
return this.afAuth.signOut().then(() => {
localStorage.removeItem('user');
this.router.navigate(['sign-in']);
})
}
}
Greetings from Mexico.