Skip to content

Commit

Permalink
feat(assets): added anonymous sign in and delete account functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyNahas committed May 23, 2018
1 parent ebb68f6 commit 985fc1a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ If you need me to support [bootstrap](https://getbootstrap.com/) please let me k
| -----------------------------------------------|:-------------:| :-------------------: |
| Sign Up | :heavy_check_mark: | :heavy_check_mark: |
| Sign In | :heavy_check_mark: | :heavy_check_mark: |
| Sign In Anonymously | :heavy_check_mark: | :x: |
| Sign In with Google | :heavy_check_mark: | :heavy_check_mark: |
| Sign In with Facebook | :heavy_check_mark: | :heavy_check_mark: |
| Sign In with Twitter | :heavy_check_mark: | :heavy_check_mark: |
Expand All @@ -46,6 +47,7 @@ If you need me to support [bootstrap](https://getbootstrap.com/) please let me k
| Forgot/Reset Password | :heavy_check_mark: | :x: |
| Delete account | :heavy_check_mark: | :x: |
| User Profile | :heavy_check_mark: | :x: |
| Check whether user's email is verified | :heavy_check_mark: | :x: |
| Edit User (name, email) | :heavy_check_mark: | :x: |
| Configure your favorite auth provider in runtime| :heavy_check_mark: | :x: |
| Sync user'auth with Firestore | :heavy_check_mark: | :x: |
Expand Down Expand Up @@ -76,6 +78,7 @@ If you need me to support [bootstrap](https://getbootstrap.com/) please let me k
- <ngx-auth-firebaseui-user> used to diplasy/edit the data of the current authenticated user

## Supported Providers:
- anonymously
- email and password (traditional)
- google
- facebook
Expand All @@ -86,6 +89,7 @@ If you need me to support [bootstrap](https://getbootstrap.com/) please let me k
## Supported Processes and Actions:
- sign up
- sign in
- sign in Anonymously
- validation of password's strength while creating a new account using [ngx-material-password-strength](https://github.com/AnthonyNahas/ngx-material-password-strength)
- forgot/reset password
- sending email verifications
Expand Down
41 changes: 36 additions & 5 deletions src/module/services/auth-process.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import {AngularFireAuth} from 'angularfire2/auth';
import {ISignInProcess, ISignUpProcess} from '../interfaces/main.interface';
import {FirestoreSyncService} from './firestore-sync.service';
import * as firebase from 'firebase';
import User = firebase.User;
// import User = firebase.User;
import GoogleAuthProvider = firebase.auth.GoogleAuthProvider;
import FacebookAuthProvider = firebase.auth.FacebookAuthProvider;
import TwitterAuthProvider = firebase.auth.TwitterAuthProvider;
import UserCredential = firebase.auth.UserCredential;
import GithubAuthProvider = firebase.auth.GithubAuthProvider;
import {Accounts} from '../enums';

export enum AuthProvider {
ALL = 'all',
ANONYMOUS = 'anonymous',
EmailAndPassword = 'firebase',
Google = 'google',
Facebook = 'facebook',
Expand Down Expand Up @@ -60,11 +62,16 @@ export class AuthProcessService implements ISignInProcess, ISignUpProcess {
public async signInWith(provider: AuthProvider, email?: string, password?: string) {
try {
this.isLoading = true;
let signInResult: User | UserCredential;
let signInResult: firebase.User | UserCredential;

switch (provider) {
case AuthProvider.ANONYMOUS:
signInResult = await this.auth.auth.signInAnonymously() as firebase.User;
await this._fireStoreService.updateUserData(signInResult);
this._snackBar.open(`Hallo ${signInResult.displayName ? signInResult.displayName : ''}!`, 'OK', {duration: 5000});
return this.onSuccessEmitter.next(signInResult);
case AuthProvider.EmailAndPassword:
signInResult = await this.auth.auth.signInWithEmailAndPassword(email, password) as User;
signInResult = await this.auth.auth.signInWithEmailAndPassword(email, password) as firebase.User;
await this._fireStoreService.updateUserData(signInResult);
this._snackBar.open(`Hallo ${signInResult.displayName ? signInResult.displayName : ''}!`, 'OK', {duration: 5000});
return this.onSuccessEmitter.next(signInResult);
Expand Down Expand Up @@ -115,15 +122,15 @@ export class AuthProcessService implements ISignInProcess, ISignUpProcess {
try {
this.isLoading = true;
console.log(`name: ${name} | email: ${email} --> ${password}`);
const user: User = await this.auth.auth.createUserWithEmailAndPassword(email, password);
const user: firebase.User = await this.auth.auth.createUserWithEmailAndPassword(email, password);
await this._fireStoreService
.getUserDocRefByUID(user.uid)
.set({
uid: user.uid,
displayName: name,
email: user.email,
photoURL: user.photoURL
} as User);
} as firebase.User);
console.log('on sign up with user', user);
await user.sendEmailVerification();
const updatedProfileResult = await this.updateProfile(name, user.photoURL);
Expand Down Expand Up @@ -153,6 +160,30 @@ export class AuthProcessService implements ISignInProcess, ISignUpProcess {
return await this.auth.auth.currentUser.updateProfile({displayName: name, photoURL: photoURL});
}

public async deleteAccount(): Promise<any> {
return await this.auth.auth.currentUser.delete();
}

public getUserPhotoUrl(): string {

const user: firebase.User | null = this.auth.auth.currentUser;

if (user.photoURL) {
console.log('user.photoURL = ', user.photoURL);
return user.photoURL;
} else if (user.emailVerified) {
return this.getPhotoPath(Accounts.CHECK);
} else if (user.isAnonymous) {
return this.getPhotoPath(Accounts.OFF);
} else {
return this.getPhotoPath(Accounts.NONE);
}
}

public getPhotoPath(image: string) {
return `assets/user/${image}.svg`;
}

public signInWithPhoneNumber() {
// todo: 3.1.18
}
Expand Down

0 comments on commit 985fc1a

Please sign in to comment.