Fireship · @fireship
Angular Ngrx with Firebase Google OAuth User Authentication
Uploaded September 6, 2017 · Length 8:40
Summary
Implement Google OAuth user authentication with Firebase in Angular using Ngrx for state management.
- angular ngrx firebase authentication
- google oauth angular
- firebase angular user authentication
- ngrx state management
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
User authentication involves some of the most critical data that a JavaScript app will have
- 0:04
to manage.
- 0:05
In this lesson, we're going to implement Google OAuth via Firebase, but we're going to do
- 0:09
it using NGRX and the one-way data flow of Redux.
- 0:13
I'd like to point out that this video is going to cover a lot of code very quickly,
- 0:17
so if you're brand new to NGRX, check out some of the links in the description for an
- 0:21
easier introduction into Redux.
- 0:23
The feature we're building today will check if a user signed in, and if not, they can sign
- 0:27
in via Google and then sign out.
- 0:29
And all this will be kept in a single data store through NGRX.
- 0:33
The first step is to add the necessary files to the NG module.
- 0:37
We're going to need AngularFire 2 along with NGRX Store and Effects.
- 0:42
Then we're going to build our own User Effects and User Reducer.
- 0:46
So we add everything to the import section and we're good to go.
- 0:50
The next step is to model our user data.
- 0:53
We're going to keep the user interface as simple as possible.
- 0:55
It'll just have a user ID display name and then an optional property for loading and an optional property for error
- 1:02
Then we'll create a user class that uses these properties and build it by passing it a user ID and display name that we get back from
- 1:09
Firebase
- 1:10
From here we can start building our user actions
- 1:13
The first and probably most important action is get user which will determine if the user is currently authenticated in Firebase
- 1:20
If they are authenticated then we'll run an authenticated action that will update
- 1:25
the current user data on the data store. If they're not authenticated then we'll
- 1:29
run a not authenticated action that will just set a default guest user on the
- 1:34
data store. Then to log in or sign up user we'll set up a Google login action
- 1:39
and we'll also give the user the ability to log out and we'll set one more action
- 1:44
for auth error just to handle any errors that might come up. Now each of these
- 1:49
actions will get its own class that implements the action interface. It will have a read-only
- 1:54
type that corresponds to the constant above, and the constructor allows it to handle a data
- 1:58
payload if necessary. To keep this part brief, we're just going to follow the same exact


