Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form [formGroup]="forma" (ngSubmit)="emailSignUp()" novalidate>
- <!-- <div class="form-group">
- <input type="text" class="form-control" placeholder="Nombre" formControlName="displayName">
- </div> -->
- <div class="form-group">
- <input type="email" class="form-control" placeholder="Email" formControlName="email">
- </div>
- <div class="form-group">
- <input type="password" class="form-control" placeholder="Contraseña" formControlName="password">
- </div>
- <div class="my-2">
- <button class="btn btn-primary btn-block" type="submit" >Crear cuenta</button>
- </div>
- </form>
- this.forma = fb.group ({
- //displayName: ['', Validators.required],
- email: [ '', [Validators.required, Validators.email] ],
- password: [ '', Validators.required ],
- })
- emailSignUp() {
- this.auth.emailSignUp(this.forma.value.email, this.forma.value.password)
- }
- interface User {
- uid: string;
- email: string;
- photoURL?: string;
- displayName?: string;
- favoriteColor?: string;
- fechaRegistro?: string;
- }
- constructor( private afAuth: AngularFireAuth, private afs: AngularFirestore) {
- this.user = this.afAuth.authState.pipe(
- switchMap(user => {
- if (user) {
- return this.afs.doc<User>(`users/${user.uid}`).valueChanges()
- } else {
- return of(null)
- }
- })
- )
- }
- emailSignUp(email: string, password: string) {
- return this.afAuth.auth
- .createUserWithEmailAndPassword(email, password)
- .then(credential => {
- this.pushUserData(credential.user);
- console.log('Usuario creado')
- this.router.navigate(['/login'])
- })
- .catch(error => {
- this.handleError(error)
- });
- }
- private pushUserData( user: User ) {
- const userRef: AngularFirestoreDocument<User> = this.afs.doc(`users/${user.uid}`);
- const data: User = {
- uid: user.uid,
- email: user.email,
- };
- userRef.set(data, {merge: true});
- }
Add Comment
Please, Sign In to add comment