create user on firebase
This commit is contained in:
parent
84d007ce7f
commit
4b791f53ca
3 changed files with 49 additions and 2 deletions
|
|
@ -83,14 +83,16 @@
|
||||||
<div class="error-msg">
|
<div class="error-msg">
|
||||||
@if (!password.valid && password.touched) {
|
@if (!password.valid && password.touched) {
|
||||||
<p>You must enter a password.</p>
|
<p>You must enter a password.</p>
|
||||||
}
|
} @else { @if (registerData.password.length < 6 && password.touched) {
|
||||||
|
<p>The password must consist of at least 6 characters</p>
|
||||||
|
} }
|
||||||
</div>
|
</div>
|
||||||
<input
|
<input
|
||||||
type="passwordConfirm"
|
type="passwordConfirm"
|
||||||
id="passwordConfirm"
|
id="passwordConfirm"
|
||||||
name="passwordConfirm"
|
name="passwordConfirm"
|
||||||
#passwordConfirm="ngModel"
|
#passwordConfirm="ngModel"
|
||||||
placeholder="Password"
|
placeholder="Confirm Password"
|
||||||
class="custom-input"
|
class="custom-input"
|
||||||
[(ngModel)]="registerData.passwordConfirm"
|
[(ngModel)]="registerData.passwordConfirm"
|
||||||
required
|
required
|
||||||
|
|
@ -107,6 +109,9 @@
|
||||||
<div class="error-msg">
|
<div class="error-msg">
|
||||||
@if (!passwordConfirm.valid && passwordConfirm.touched) {
|
@if (!passwordConfirm.valid && passwordConfirm.touched) {
|
||||||
<p>You must enter a password.</p>
|
<p>You must enter a password.</p>
|
||||||
|
} @if (registerData.password !== registerData.passwordConfirm &&
|
||||||
|
registerData.password !== "" && registerData.passwordConfirm !== "") {
|
||||||
|
<p>The passwords don't match!</p>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -121,6 +126,8 @@
|
||||||
password.invalid ||
|
password.invalid ||
|
||||||
!registerData.password ||
|
!registerData.password ||
|
||||||
sharedService.isBtnDisabled ||
|
sharedService.isBtnDisabled ||
|
||||||
|
registerData.password.length < 6 ||
|
||||||
|
registerData.password !== registerData.passwordConfirm ||
|
||||||
!checkIfUserEmailIsValid(registerData.mail)
|
!checkIfUserEmailIsValid(registerData.mail)
|
||||||
"
|
"
|
||||||
></app-form-btn>
|
></app-form-btn>
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@ export class RegisterComponent {
|
||||||
name: '',
|
name: '',
|
||||||
mail: '',
|
mail: '',
|
||||||
password: '',
|
password: '',
|
||||||
|
color: '',
|
||||||
|
initials: '',
|
||||||
passwordConfirm: '',
|
passwordConfirm: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -41,6 +43,7 @@ export class RegisterComponent {
|
||||||
this.sharedService.isBtnDisabled = true;
|
this.sharedService.isBtnDisabled = true;
|
||||||
if (ngForm.submitted && ngForm.form.valid) {
|
if (ngForm.submitted && ngForm.form.valid) {
|
||||||
//this.loginSerivce.register(this.registerData);
|
//this.loginSerivce.register(this.registerData);
|
||||||
|
console.log(this.registerData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import {
|
||||||
signInWithEmailAndPassword,
|
signInWithEmailAndPassword,
|
||||||
signInWithPopup,
|
signInWithPopup,
|
||||||
GoogleAuthProvider,
|
GoogleAuthProvider,
|
||||||
|
Auth,
|
||||||
} from 'firebase/auth';
|
} from 'firebase/auth';
|
||||||
import { FirebaseService } from './firebase.service';
|
import { FirebaseService } from './firebase.service';
|
||||||
import {
|
import {
|
||||||
|
|
@ -48,6 +49,39 @@ export class LoginService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
register(registerData: {
|
||||||
|
name: string;
|
||||||
|
mail: string;
|
||||||
|
password: string;
|
||||||
|
initials: string;
|
||||||
|
color: string;
|
||||||
|
}) {
|
||||||
|
signInWithEmailAndPassword(
|
||||||
|
getAuth(),
|
||||||
|
registerData.mail,
|
||||||
|
registerData.password
|
||||||
|
)
|
||||||
|
.then((userCredential) => {
|
||||||
|
const user = userCredential.user;
|
||||||
|
|
||||||
|
const userDataToSave: User = {
|
||||||
|
uId: user.uid,
|
||||||
|
email: user.email || '',
|
||||||
|
firstName: registerData.name || '',
|
||||||
|
lastName: registerData.name || '',
|
||||||
|
status: true,
|
||||||
|
phone: '',
|
||||||
|
initials: registerData.initials,
|
||||||
|
color: registerData.color,
|
||||||
|
lastLogin: new Date().getTime(),
|
||||||
|
};
|
||||||
|
this.createUserInFirestore(userDataToSave);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
googleLogin() {
|
googleLogin() {
|
||||||
const auth = getAuth();
|
const auth = getAuth();
|
||||||
const provider = new GoogleAuthProvider();
|
const provider = new GoogleAuthProvider();
|
||||||
|
|
@ -129,3 +163,6 @@ export class LoginService {
|
||||||
localStorage.setItem('currentUserJOIN', JSON.stringify(userId));
|
localStorage.setItem('currentUserJOIN', JSON.stringify(userId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function createUserWithEmailAndPassword(auth: Auth, email: any, password: any) {
|
||||||
|
throw new Error('Function not implemented.');
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue