Fireship · @fireship

Multi-Step Password Auth with Firebase and Reactive Forms

Uploaded November 14, 2017 · Length 11:22

Multi-Step Password Auth with Firebase and Reactive Forms

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.

  1. 0:00

    fire base makes basic user

  2. 0:01

    authentication very easy but what

  3. 0:03

    happens if you require additional data

  4. 0:05

    from your user before they're authorized

  5. 0:06

    to start using your app in this episode

  6. 0:09

    I'm going to set up a multi-step signup

  7. 0:11

    form that requires the user to fill out

  8. 0:12

    a catchphrase on their user profile

  9. 0:14

    before they're authorized to start using

  10. 0:16

    the app then we're going to secure all

  11. 0:18

    the application data on both the front

  12. 0:20

    end and the back end this feature works

  13. 0:22

    by setting up a custom user document in

  14. 0:24

    the firestore database we can then

  15. 0:26

    verify that the current user has the

  16. 0:28

    correct information on their document

  17. 0:30

    before they're authorized to perform

  18. 0:31

    certain actions in order to build this

  19. 0:33

    feature I'm going to be using the fire

  20. 0:35

    starter demo app which is on github you

  21. 0:37

    can clone it if you want but this code

  22. 0:39

    can be applied to any angular app that's

  23. 0:41

    using firebase but before we get started

  24. 0:43

    make sure to subscribe and you can find

  25. 0:46

    all the source code at angular firebase

  26. 0:48

    com the first place we're going to start

  27. 0:50

    is in the auth service and in my case

  28. 0:52

    it's in that core module the goal with

  29. 0:54

    the service is to keep track of the

  30. 0:56

    current user and give them the ability

  31. 0:57

    to sign in via email and password the

  32. 1:00

    important imports to take note of here

  33. 1:02

    are angularfire auth and angular fire

  34. 1:04

    store as well as the switch map operator

  35. 1:07

    from rxjs the first thing I'm going to

  36. 1:09

    do is set up an interface to model our

  37. 1:11

    user data we need to have a user ID and

  38. 1:13

    email address which we'll get from

  39. 1:15

    firebase auth and then our custom piece

  40. 1:17

    of data is the catchphrase notice that

  41. 1:19

    you don't need to actually add the

  42. 1:21

    password to the user interface that's

  43. 1:22

    all handled by angularfire auth so our

  44. 1:25

    actual user is going to be an observable

  45. 1:27

    type to this interface then we'll inject

  46. 1:29

    our dependencies in the constructor the

  47. 1:31

    notify service that I'm adding here is

  48. 1:33

    part of the demo app it's not required

  49. 1:35

    but it's used to show the end-user any

  50. 1:37

    problems with the sign-in process then

  51. 1:40

    inside the constructor we'll define the

  52. 1:41

    user variable so we do this by calling

  53. 1:44

    angularfire auth state which gives us an

  54. 1:46

    observable that we can call switch map

  55. 1:48

    on if the current user is logged in then

  56. 1:50

    we'll go ahead and retrieve the user

  57. 1:52

    data from fire store we do that by

  58. 1:54

    calling AFS doc and then point to that

  59. 1:57

    current users user ID and then call

  60. 1:59

    value changes to get the observable if