Angular 4 Firebase Auth – Anonymous Authentication with AngularFire2 v4

Anonymous authentication uses only a userID to login without registration. Once signing out, user will not be able to log back in. In this tutorial, we’re gonna look at way to implement Anonymous authentication with AngularFire2 v4.

Related Post:
How to integrate Firebase with Angular 4

More Practice:
Angular 4 Firebase Auth – Email/Password Authentication with AngularFire2 v4

I. Technology

– Angular 4
– AngularFire2 4.0

II. Overview

We will build an Angular 4 App that allows user login anonymously:

angular-4-firebase-auth-anonymous-overview

II. How to do

1. Set up the Firebase Project & Install AngularFire2

Please visit this post to know step by step.

angular-4-firebase-integration-copy-firebase-project-config

2. Enable Firebase Auth for Anonymous

Go to your Project on Firebase Console -> Authentication tab -> SIGN-IN METHOD -> enable Anonymous:

angular-4-firebase-auth-anonymous-enable-console

3. Auth Service

– We subscribe to the AngularFire auth observable that returns a FirebaseAuthState object. This object is null when logging out, and contains useful User Information (UID, Display Name, Photo URL…) when logging in.
– We use:
+ AngularFireAuth.auth.signInAnonymously() to log in.
+ AngularFireAuth.auth.signOut() to log out.

4. App Module

III. Practice

1. Project structure

angular-4-firebase-auth-anonymous-structure

2. App Module

3. Auth Service

4. Components
4.1 User Login Component

user-login.component.ts

user-login.component.html

4.2 User Info Component

user-info.component.ts

user-info.component.html

5. App Routing Module

app-routing.module.ts

6. App Component

app.component.ts

app.component.html

7. Check Result

Run the App, login and log out several times:
angular-4-firebase-auth-anonymous-overview

Firebase Console:
angular-4-firebase-auth-anonymous-console-resule

IV. Source Code

Angular4FirebaseAuth-anonymous

By JavaSampleApproach | September 11, 2017.


Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*