Advertisement
Guest User

ayuda yamil

a guest
Jul 31st, 2018
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     loginWithEmail() {
  2.         const mail = 'alexander2@gmail.com';
  3.         const pass = '1234567890';
  4.  
  5.         const login = from(this.afAuth.auth.signInWithEmailAndPassword(mail, pass));
  6.         login.subscribe(() => {
  7.             this.router.navigateByUrl('home/main');
  8.         }, err => {
  9.             const error = JSON.stringify(err);
  10.             // console.log('error login: ' + err);
  11.             if (error) {
  12.                 if (error.indexOf('no user') > -1 || error.indexOf('email address') > -1) {
  13.                     // this.user_error = true;
  14.                     // this.pass_error = true;
  15.                 }
  16.  
  17.                 if (error.indexOf('password') > -1) {
  18.                     // this.user_error = false;
  19.                     // this.pass_error = true;
  20.                 }
  21.             }
  22.         }
  23.         )
  24.  
  25.         login.pipe(
  26.             switchMap((firebaseUser: firebase.User) => {
  27.                 const user = <firebase.User>firebaseUser;
  28.                 console.log(user);
  29.                 return from((user.getIdToken()));
  30.             }),
  31.             switchMap(idToken => {
  32.                 console.log('idtoken firebase', idToken);
  33.                 return this.http.get('http://localhost:4949/auth/user')
  34.             })
  35.         ).subscribe(data => {
  36.             console.log('data user', data);
  37.             this.router.navigateByUrl('home/main');
  38.         }, err => {
  39.             const error = JSON.stringify(err);
  40.             // console.log('error login: ' + err);
  41.             if (error) {
  42.                 if (error.indexOf('no user') > -1 || error.indexOf('email address') > -1) {
  43.                     // this.user_error = true;
  44.                     // this.pass_error = true;
  45.                 }
  46.  
  47.                 if (error.indexOf('password') > -1) {
  48.                     // this.user_error = false;
  49.                     // this.pass_error = true;
  50.                 }
  51.             }
  52.         })
  53.  
  54.  
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement