firebase/app#auth TypeScript Examples

The following examples show how to use firebase/app#auth. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: login.page.ts    From Uber-ServeMe-System with MIT License 6 votes vote down vote up
async login() {
    const { email, password } = this
    try {
      const res = await this.afAuth.auth.signInWithEmailAndPassword(email, password)
      if(res.user) {
          this.router.navigate(['/home/feed'])
      }
    } catch(err) {
      console.dir(err)
      if (err.code === "auth/user-not-found") {
        console.log("User not found")
      }
      this.showAlert(err.message)
    }
  }
Example #2
Source File: firebase-user.service.ts    From FireAdmin with MIT License 6 votes vote down vote up
delete(email: string, password: string): Promise<any> {
    return new Promise((resolve, reject) => {
      this.app.auth().signInWithEmailAndPassword(email, password).then(() => {
        this.app.auth().currentUser.delete().then(() => {
          resolve();
        }).catch((error: firebase.FirebaseError) => {
          reject(error);
        }).finally(() => {
          this.app.auth().signOut();
        });
      }).catch((error: firebase.FirebaseError) => {
        reject(error);
      });
    });
  }
Example #3
Source File: firebase-user.service.ts    From FireAdmin with MIT License 6 votes vote down vote up
updatePassword(email: string, password: string, newPassword: string): Promise<any> {
    return new Promise((resolve, reject) => {
      this.app.auth().signInWithEmailAndPassword(email, password).then(() => {
        this.app.auth().currentUser.updatePassword(newPassword).then(() => {
          resolve();
        }).catch((error: firebase.FirebaseError) => {
          reject(error);
        }).finally(() => {
          this.app.auth().signOut();
        });
      }).catch((error: firebase.FirebaseError) => {
        reject(error);
      });
    });
  }
Example #4
Source File: firebase-user.service.ts    From FireAdmin with MIT License 6 votes vote down vote up
updateEmail(email: string, password: string, newEmail: string): Promise<any> {
    return new Promise((resolve, reject) => {
      this.app.auth().signInWithEmailAndPassword(email, password).then(() => {
        this.app.auth().currentUser.updateEmail(newEmail).then(() => {
          resolve();
        }).catch((error: firebase.FirebaseError) => {
          reject(error);
        }).finally(() => {
          this.app.auth().signOut();
        });
      }).catch((error: firebase.FirebaseError) => {
        reject(error);
      });
    });
  }
Example #5
Source File: firebase-user.service.ts    From FireAdmin with MIT License 6 votes vote down vote up
register(user: User): Promise<string> {
    return new Promise((resolve, reject) => {
      this.app.auth().createUserWithEmailAndPassword(user.email, user.password).then((userCredential: auth.UserCredential) => {
        // console.log('User ' + userCredential.user.uid + ' created successfully!');
        this.app.firestore().collection('users').doc(userCredential.user.uid).set(user).then(() => {
          this.app.firestore().collection('config').doc('registration').set({ enabled: false }, { merge: true }).then(() => {
            this.app.auth().signOut();
            resolve(userCredential.user.uid);
          }).catch((error: firebase.FirebaseError) => {
            this.app.auth().signOut();
            reject(error);
          });
        }).catch((error: firebase.FirebaseError) => {
          this.app.auth().signOut();
          reject(error);
        });
      }).catch((error: firebase.FirebaseError) => {
        reject(error);
      });
    });
  }
Example #6
Source File: firebase-user.service.ts    From FireAdmin with MIT License 6 votes vote down vote up
create(email: string, password: string): Promise<string> {
    return new Promise((resolve, reject) => {
      this.app.auth().createUserWithEmailAndPassword(email, password).then((userCredential: auth.UserCredential) => {
        // console.log('User ' + userCredential.user.uid + ' created successfully!');
        this.app.auth().signOut();
        resolve(userCredential.user.uid);
      }).catch((error: firebase.FirebaseError) => {
        reject(error);
      });
    });
  }
Example #7
Source File: auth.service.ts    From FireAdmin with MIT License 6 votes vote down vote up
signOut(force: boolean = false): Promise<void> {
    // console.log('sign out', this.firebaseUser);
    return new Promise((resolve, reject) => {
      if (force || !!this.firebaseUser) {
        this.afa.auth.signOut().then(() => {
          resolve();
        }).catch((error: firebase.FirebaseError) => {
          this.setLastError(error);
          reject(this.lastError);
        });
      } else {
        resolve();
      }
    });
  }
Example #8
Source File: auth.service.ts    From FireAdmin with MIT License 6 votes vote down vote up
signIn(email: string, password: string, isPersistent: boolean = false): Promise<void> {
    // console.log('sign in', email, password);
    return new Promise((resolve, reject) => {
      if (!!this.firebaseUser) {
        console.log('already signed in!');
        resolve();
      } else {
        // Sign in
        const persistence = isPersistent ? auth.Auth.Persistence.LOCAL : auth.Auth.Persistence.SESSION;
        this.afa.auth.setPersistence(persistence).then(() => {
          this.afa.auth.signInWithEmailAndPassword(email, password).then(() => {
            resolve();
          }).catch((error: firebase.FirebaseError) => {
            this.setLastError(error);
            reject(this.lastError);
          });
        }).catch((error: firebase.FirebaseError) => {
          this.setLastError(error);
          reject(this.lastError);
        });
      }
    });
  }
Example #9
Source File: user.service.ts    From Uber-ServeMe-System with MIT License 6 votes vote down vote up
getOrders() {
		return this.firestore.doc(`users/${this.afAuth.auth.currentUser.uid}`).collection('orders').stateChanges().pipe(
			map(actions => {
				return actions.map(a => {
					const data = a.payload.doc.data()
					const id = a.payload.doc.id
					return {id, ...data}
				})
			})
		)
	}
Example #10
Source File: login.page.ts    From Uber-ServeMe-System with MIT License 6 votes vote down vote up
successCallback() {
    if(this.afstore.doc(`users/${this.afAuth.auth.currentUser.uid}`).get()) {
      this.afstore.doc(`users/${this.afAuth.auth.currentUser.uid}`).set({
        email: this.afAuth.auth.currentUser.email,
        lastname: "Please edit",
        firstname: "",
      })
    }
    this.router.navigate(['/home/feed'])
  }
Example #11
Source File: user.service.ts    From Uber-ServeMe-System with MIT License 5 votes vote down vote up
updateNewPassword(newpassword: string) {
		this.firestore.doc(`users/${this.afAuth.auth.currentUser.uid}`).update({password: newpassword});
	}
Example #12
Source File: user.service.ts    From Uber-ServeMe-System with MIT License 5 votes vote down vote up
getAuth() {
		return this.afAuth.auth
	}
Example #13
Source File: user.service.ts    From Uber-ServeMe-System with MIT License 5 votes vote down vote up
addOrder(orderData: any) {
		this.firestore.doc(`users/${this.afAuth.auth.currentUser.uid}`).collection('orders').add(orderData)
		console.log("order successful written")
	}
Example #14
Source File: user.service.ts    From Uber-ServeMe-System with MIT License 5 votes vote down vote up
updatePassword(newpassword: string) {
		return this.afAuth.auth.currentUser.updatePassword(newpassword)
	}
Example #15
Source File: user.service.ts    From Uber-ServeMe-System with MIT License 5 votes vote down vote up
updateEmail(newemail: string) {
		return this.afAuth.auth.currentUser.updateEmail(newemail)
	}
Example #16
Source File: user.service.ts    From Uber-ServeMe-System with MIT License 5 votes vote down vote up
updateLastName(newname: string) {
		this.firestore.doc(`users/${this.afAuth.auth.currentUser.uid}`).update({lastname: newname});
	}
Example #17
Source File: auth.service.ts    From FireAdmin with MIT License 5 votes vote down vote up
constructor(private afa: AngularFireAuth, private currentUser: CurrentUserService) {
    this.afa.auth.onAuthStateChanged((user: firebase.User) => {
      // console.log(user);
      this.firebaseUser = user;
      this.currentUser.set(user);
    });
  }
Example #18
Source File: user.service.ts    From Uber-ServeMe-System with MIT License 5 votes vote down vote up
updateFirstName(newname: string) {
		this.firestore.doc(`users/${this.afAuth.auth.currentUser.uid}`).update({firstname: newname});
	}
Example #19
Source File: user.service.ts    From Uber-ServeMe-System with MIT License 5 votes vote down vote up
getUserEmail(): string {
		return this.afAuth.auth.currentUser.email
	}
Example #20
Source File: user.service.ts    From Uber-ServeMe-System with MIT License 5 votes vote down vote up
reAuth(email: string, password: string) {
		return this.afAuth.auth.currentUser.reauthenticateWithCredential(auth.EmailAuthProvider.credential(email, password))
	}
Example #21
Source File: login.page.ts    From Uber-ServeMe-System with MIT License 5 votes vote down vote up
signOut() {
    this.afAuth.auth.signOut().then(() => {
      this.router.navigate(['/'])
    })
  }