Fireship · @fireship
Multi-Step Password Auth with Firebase and Reactive Forms
Uploaded November 14, 2017 · Length 11:22
Summary
Implementing multi-step password authentication with Firebase and Reactive Forms in Angular, including custom user documents and form validation.
- firebase authentication
- reactive forms angular
- multi-step signup form
- custom user documents
- angular firebase integration
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
fire base makes basic user
- 0:01
authentication very easy but what
- 0:03
happens if you require additional data
- 0:05
from your user before they're authorized
- 0:06
to start using your app in this episode
- 0:09
I'm going to set up a multi-step signup
- 0:11
form that requires the user to fill out
- 0:12
a catchphrase on their user profile
- 0:14
before they're authorized to start using
- 0:16
the app then we're going to secure all
- 0:18
the application data on both the front
- 0:20
end and the back end this feature works
- 0:22
by setting up a custom user document in
- 0:24
the firestore database we can then
- 0:26
verify that the current user has the
- 0:28
correct information on their document
- 0:30
before they're authorized to perform
- 0:31
certain actions in order to build this
- 0:33
feature I'm going to be using the fire
- 0:35
starter demo app which is on github you
- 0:37
can clone it if you want but this code
- 0:39
can be applied to any angular app that's
- 0:41
using firebase but before we get started
- 0:43
make sure to subscribe and you can find
- 0:46
all the source code at angular firebase
- 0:48
com the first place we're going to start
- 0:50
is in the auth service and in my case
- 0:52
it's in that core module the goal with
- 0:54
the service is to keep track of the
- 0:56
current user and give them the ability
- 0:57
to sign in via email and password the
- 1:00
important imports to take note of here
- 1:02
are angularfire auth and angular fire
- 1:04
store as well as the switch map operator
- 1:07
from rxjs the first thing I'm going to
- 1:09
do is set up an interface to model our
- 1:11
user data we need to have a user ID and
- 1:13
email address which we'll get from
- 1:15
firebase auth and then our custom piece
- 1:17
of data is the catchphrase notice that
- 1:19
you don't need to actually add the
- 1:21
password to the user interface that's
- 1:22
all handled by angularfire auth so our
- 1:25
actual user is going to be an observable
- 1:27
type to this interface then we'll inject
- 1:29
our dependencies in the constructor the
- 1:31
notify service that I'm adding here is
- 1:33
part of the demo app it's not required
- 1:35
but it's used to show the end-user any
- 1:37
problems with the sign-in process then
- 1:40
inside the constructor we'll define the
- 1:41
user variable so we do this by calling
- 1:44
angularfire auth state which gives us an
- 1:46
observable that we can call switch map
- 1:48
on if the current user is logged in then
- 1:50
we'll go ahead and retrieve the user
- 1:52
data from fire store we do that by
- 1:54
calling AFS doc and then point to that
- 1:57
current users user ID and then call
- 1:59
value changes to get the observable if


