Fireship · @fireship
Google Sign-In with Firestore Custom User Data
Uploaded October 12, 2017 · Length 7:52
Summary
Implement custom user data with Firebase Firestore and Google Sign-In in an Angular app.
- firebase
- firestore
- google-sign-in
- angular
- custom-user-data
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
Firebase makes user authentication
- 0:01
incredibly easy to implement in angular
- 0:04
but the one drawback is that it's not
- 0:05
easy to implement custom data on the off
- 0:08
object itself in this episode I'm going
- 0:10
to show you how to implement an ooth
- 0:12
system from scratch using angular fire
- 0:14
version 5 and also save custom user data
- 0:17
to the fir store database in addition
- 0:19
we're going to set up a router guard
- 0:21
that will prevent unauthorized users
- 0:22
from accessing certain routes I
- 0:25
recommend that you follow along with the
- 0:26
source code on angular firebase.com and
- 0:29
make sure to subscribe to the channel
- 0:30
for a bunch of updates regarding fir
- 0:32
store in the near future to get started
- 0:35
the first thing you'll need is a
- 0:36
Firebase account and make sure you have
- 0:38
the Google login provider enabled I'm
- 0:41
also assuming that you have an existing
- 0:42
angular project with angular fire
- 0:44
installed if not go to the angular fire
- 0:46
docs and follow the setup instructions
- 0:48
for version 5 the first thing I'm going
- 0:50
to do is create a core module which is
- 0:52
used in angular to handle Global
- 0:54
Services within your app such as
- 0:56
authentication the core module is
- 0:58
technically optional but it is
- 0:59
considered a good practice once you have
- 1:01
it generated add it to the import
- 1:04
section of the app module then we can
- 1:06
jump over to the core module and we'll
- 1:08
add angular fire off and angular fire
- 1:10
store I also have an off service in here
- 1:12
which we're going to generate in The
- 1:14
Next
- 1:15
Step the off service is going to handle
- 1:17
most of the heavy lifting when you
- 1:19
generate it make sure to use the m flag
- 1:21
so it gets added to the core module
- 1:23
automatically inside of our service
- 1:25
we're going to import the angular router
- 1:28
as well as the angular fire o and Fir
- 1:30
store Services we're also going to use
- 1:32
the rxjs observable class and the switch
- 1:35
map operator as you'll see here in just
- 1:37
a second the nice thing about our
- 1:38
service is we can define an interface
- 1:40
with any custom data that we want to add
- 1:42
to it so here I'm going to add a user
- 1:44
interface and I'll just add a few
- 1:46
default values here that come with the
- 1:48
normal Firebase off State and then I'll
- 1:51
also add a custom attribute for favorite
- 1:54
color but you could add anything you
- 1:55
want here then the next thing we'll do
- 1:57
is set a variable on the service that is


