Fireship · @fireship

Google Sign-In with Firestore Custom User Data

Uploaded October 12, 2017 · Length 7:52

Google Sign-In with Firestore Custom User Data

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.

  1. 0:00

    Firebase makes user authentication

  2. 0:01

    incredibly easy to implement in angular

  3. 0:04

    but the one drawback is that it's not

  4. 0:05

    easy to implement custom data on the off

  5. 0:08

    object itself in this episode I'm going

  6. 0:10

    to show you how to implement an ooth

  7. 0:12

    system from scratch using angular fire

  8. 0:14

    version 5 and also save custom user data

  9. 0:17

    to the fir store database in addition

  10. 0:19

    we're going to set up a router guard

  11. 0:21

    that will prevent unauthorized users

  12. 0:22

    from accessing certain routes I

  13. 0:25

    recommend that you follow along with the

  14. 0:26

    source code on angular firebase.com and

  15. 0:29

    make sure to subscribe to the channel

  16. 0:30

    for a bunch of updates regarding fir

  17. 0:32

    store in the near future to get started

  18. 0:35

    the first thing you'll need is a

  19. 0:36

    Firebase account and make sure you have

  20. 0:38

    the Google login provider enabled I'm

  21. 0:41

    also assuming that you have an existing

  22. 0:42

    angular project with angular fire

  23. 0:44

    installed if not go to the angular fire

  24. 0:46

    docs and follow the setup instructions

  25. 0:48

    for version 5 the first thing I'm going

  26. 0:50

    to do is create a core module which is

  27. 0:52

    used in angular to handle Global

  28. 0:54

    Services within your app such as

  29. 0:56

    authentication the core module is

  30. 0:58

    technically optional but it is

  31. 0:59

    considered a good practice once you have

  32. 1:01

    it generated add it to the import

  33. 1:04

    section of the app module then we can

  34. 1:06

    jump over to the core module and we'll

  35. 1:08

    add angular fire off and angular fire

  36. 1:10

    store I also have an off service in here

  37. 1:12

    which we're going to generate in The

  38. 1:14

    Next

  39. 1:15

    Step the off service is going to handle

  40. 1:17

    most of the heavy lifting when you

  41. 1:19

    generate it make sure to use the m flag

  42. 1:21

    so it gets added to the core module

  43. 1:23

    automatically inside of our service

  44. 1:25

    we're going to import the angular router

  45. 1:28

    as well as the angular fire o and Fir

  46. 1:30

    store Services we're also going to use

  47. 1:32

    the rxjs observable class and the switch

  48. 1:35

    map operator as you'll see here in just

  49. 1:37

    a second the nice thing about our

  50. 1:38

    service is we can define an interface

  51. 1:40

    with any custom data that we want to add

  52. 1:42

    to it so here I'm going to add a user

  53. 1:44

    interface and I'll just add a few

  54. 1:46

    default values here that come with the

  55. 1:48

    normal Firebase off State and then I'll

  56. 1:51

    also add a custom attribute for favorite

  57. 1:54

    color but you could add anything you

  58. 1:55

    want here then the next thing we'll do

  59. 1:57

    is set a variable on the service that is