angular / angularfire

Angular + Firebase = ❤️
https://firebaseopensource.com/projects/angular/angularfire2
MIT License
7.69k stars 2.19k forks source link

EMAIL/password Authentication #973

Closed hASVAN closed 7 years ago

hASVAN commented 7 years ago

Looking at this solution angular2

` state: string = ''; error: any;

constructor(public af: AngularFire,private router: Router) {
this.af.auth.subscribe(auth => { 
  if(auth) {
    this.router.navigateByUrl('/members');
  }
});

}

onSubmit(formData) { if(formData.valid) { console.log(formData.value); this.af.auth.login({ email: formData.value.email, password: formData.value.password }, { provider: AuthProviders.Password, method: AuthMethods.Password, }).then( (success) => { console.log(success); this.router.navigate(['/members']); }).catch( (err) => { console.log(err); this.error = err; }) } }`

I have been trying to get the same functionality to work in angular4

Property 'login' does not exist on type 'Observable'

Here is some sample code (not working):

`import { routing } from './app.routing'; import { Router, ActivatedRoute, Params } from '@angular/router'; import { Observable } from 'rxjs/Observable'; import { FirebaseObjectFactoryOpts } from "angularfire2/interfaces"; import { AngularFireDatabaseModule, AngularFireDatabase, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2/database'; import { AngularFireAuthModule, AngularFireAuth } from 'angularfire2/auth'; import * as firebase from 'firebase/app';

@Component({ selector: 'app', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { state: string = ''; error: any;

constructor(private afAuth: AngularFireAuth, private db: AngularFireDatabase,private router: Router) { this.afAuth.authState.subscribe(auth => { if(auth) { this.router.navigateByUrl('/members'); } }); }

onSubmit(formData) { if(formData.valid) { console.log(formData.value); this.afAuth.authState.login({ email: formData.value.email, password: formData.value.password }, { provider: AuthProviders.Password, method: AuthMethods.Password, }).then( (success) => { console.log(success); this.router.navigate(['/members']); }).catch( (err) => { console.log(err); this.error = err; }) } } } `

and thx

ghost commented 7 years ago

just substitute signInWithEmailAndPassword for login

davideast commented 7 years ago

@hASVAN Please consult stackoverflow for these type of questions