Firebase Functions Tutorial #8 - Auth Triggers
Skills:
Backend Performance70%
Key Takeaways
Creates an auth trigger function using Firebase Functions for new user sign-ups
Full Transcript
okay they're my friends so we've seen already two types of direct attp triggers on request and on call now these would direct triggers that run basically when we told them to either by was using an endpoint or by calling the function from our code now there are other types of triggers called background trees and these are events that occur in the background of our app or websites so they're not directly called but when certain events occur they can trigger a cloud function to run now there's many different types of background events or background triggers we could have fire store database triggers when new records are added or deleted maybe authentication triggers and I wish these triggers cloud storage triggers and much more now the one we're going to look at first is an authentication trigger and in our case it's going to be when a new user registers so when that event occurs we're going to invoke a cloud function to do something so the first thing I like to do is delete all of the old cloud functions that were created in older tutorials because they were kind of test functions just to get us into the practice of creating them deploying them and testing them out so they don't really actually do anything useful and for that reason I'm gonna just chuck them in the bit so let's delete all of that first of all and in fact if we go to the index.html file there's a button down here that we don't really need anymore it's at the bottom of the section and it's this button which was calling the function to say hello and in fact while I'm at it the app KS all of this stuff right here we don't need that either that was always calling that on-call function and that was just a test so let's get rid of that as well now that we want to create now a cloud function a firebase function which is going to react to an authentication change and first that authentication change is going to be a new user signing up so it will be firebase creating a new user so let's do a comment and say auth trigger and this is going to be for a new user sign up now under that again we need to say exports and then give this a name I'm going to call it new user signup you can call it what you want and then that's equal to functions and we used to say HTTP and then dot either a request or on call now we don't want to do that anymore it's not an HTTP function anymore this is going to be an authentication triggered function so we say functions dot off and then dots user so this is based on something happening with the user and in our case it's going to be on create meaning when a new user is created I want you to fire a callback function and this callback function takes in that user as a parameter now because there's only one parameter I'm gonna get rid of those parentheses and now we don't always do that it's just because I forget and again to the habit of creating these functions with parentheses for some reason but anyway inside this function all I'm gonna do is say console dot log and remember that's logged over here if we take a look at the functions go to functions and in a second you're going to see this logs panel right here it's logged right here and all I'm going to do is log out a message which says user created comment and then I'm going to output the user email so user dot e mail because we get access to the email of that user and also the user dot UID that is a unique identifier for that user firebase automatically creates that when a new user signs up fortunately so that's all I'm doing in this case a new user signs up we're listening for that event so when a user is created we fire this function we take in that user that's created and we log the details to the console now I'm gonna do one more which is the exact opposite and that is going to be when a user is deleted so instead of on create it's going to be on delete so this is going to listen for users being deleted from the app and we can do that ourselves or from the backend and it's going to fire a function when that happens and again we can take in the user which is delete it and I'm going to change this to deleted from it created and I'm going to change this comments as well up here to user delete it and I'm gonna say right down here user delete it okay so now we have these two functions they both have an authentication trigger one for creation of users one when we delete a user so let's see if these work so first of all I'm gonna open up the terminal and I'm gonna say firebase deploy only functions and first of all watch what happens because we deleted the old functions that were here it's gonna ask us in a second if we actually want to delete those functions from a firebase at the backend as well and it says right here would you like to proceed with deletion so I want to so yes and press enter and it's going to delete those functions that were deleted from this file from a firebase over here as well so if we take a look at the dashboard these functions it's going to delete in a second we can already see that these have been it deployed but I am gonna wait until this is all complete before we test it out otherwise there could be some errors okay so once that is done let me go over here and refresh first of all make sure those other functions have been deleted which they have so now I'm gonna go to logs just to make sure everything's been deployed okay new user sign up and use it delete it so first of all I'm gonna try the user deleted function now to do that I'm going to open this up in a new tab authentication and we should have access to all of the users currently registered for our app now I'm gonna delete this one right here Mario at the nettinger code at UK so let me go to delete to that account press Delete and then behind the scenes this should automatically trigger that cloud function now it might take a short while to do this so let's just wait a second and refresh over here just to see if that user is logged to the salt over here okay and we can see right here use it deleted Mario and the net ninja Cody at UK and the UID of that user and by the way you can see all of the UI DS in this column and the authentication tap ok so that's worked we do have some kind of warning right here or an error in fact and we'll come to that in a second but first let me try out the other cloud function which is to create a new user so let me go to the front-end I'm going to refresh over here first of all then go to register and I'm going to register with peach at the net ninja code at UK Mario character by the way not the fruit and the password is going to be test 1 2 3 or register and hopefully this will work now if we go to our cloud functions I'm going to refresh again again it might take a few seconds to work so you might not see this automatically as I don't but now we can see it down here user created peach at the net ninja up Cody at UK and the UID for that user now like I said we are getting an error right here and this error says function returned undefined and it expected a promise of value and the same thing down here and that's because in these cloud functions right here we're not returning any kind of value now remember when we use those HTTP triggers either on call or on request we sent a response directly back to the clients either using the return keyword or by using the response object now in the case of using Blackground triggers we're not sending a response to the client because the clients has not requested anything so we don't need to send a response but we still need to return a value and in the case of background triggers it's normal to return a promise at the end so we'll address that in the next video
Original Description
Hey gang, in this Firebase Functions tutorial we'll take a look at auth triggers - functions which run when a new user signs up.
🐱👤🐱👤 JOIN THE GANG -
https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg/join
----------------------------------------
🐱💻 🐱💻 My Udemy Courses:
+ Modern JavaScript - https://www.thenetninja.co.uk/udemy/modern-javascript
+ Vue JS & Firebase - http://www.thenetninja.co.uk/udemy/vue-and-firebase
+ D3.js & Firebase - https://www.thenetninja.co.uk/udemy/d3-and-firebase
🐱💻 🐱💻 Course Files:
https://github.com/iamshaunjp/firebase-functions/tree/lesson-2
🐱💻 🐱💻 Other Related Free Courses:
+ Firebase Firestore - https://www.youtube.com/playlist?list=PL4cUxeGkcC9itfjle0ji1xOZ2cjRGY_WB
+ Firebase Authentication - https://www.youtube.com/playlist?list=PL4cUxeGkcC9jUPIes_B8vRjn1_GaplOPQ
+ Firebase Hosting - https://www.youtube.com/playlist?list=PL4cUxeGkcC9he0kHAyiyr3dDO2xw0NWoP
🐱💻 🐱💻 The Net Ninja Community Boards:
https://community.thenetninja.co.uk/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Net Ninja · Net Ninja · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
GraphQL Tutorial #5 - Express App Setup
Net Ninja
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
GraphQL Tutorial #8 - Root Query
Net Ninja
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
GraphQL Tutorial #12 - Author Type
Net Ninja
GraphQL Tutorial #13 - Type Relations
Net Ninja
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
GraphQL Tutorial #18 - Mutations
Net Ninja
GraphQL Tutorial #19 - More on Mutations
Net Ninja
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
GraphQL Tutorial #23 - Create React App
Net Ninja
GraphQL Tutorial #24 - Book List Component
Net Ninja
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
GraphQL Tutorial #28 - Add Book Component
Net Ninja
GraphQL Tutorial #29 - External Query File
Net Ninja
GraphQL Tutorial #30 - Updating Component State
Net Ninja
GraphQL Tutorial #31 - Composing Queries
Net Ninja
GraphQL Tutorial #32 - query variables
Net Ninja
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
GraphQL Tutorial #34 - Book Details Component
Net Ninja
GraphQL Tutorial #36 - Styling the App
Net Ninja
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
Updated Vue & Firebase Course (Udemy)
Net Ninja
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja
More on: Backend Performance
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Had my Frontend Developer interview with Capgemini (Application Developer) today, and I wanted to…
Medium · JavaScript
10 Frontend Developer Tools to Boost Productivity in 2026
Medium · Programming
10 Frontend Developer Tools to Boost Productivity in 2026
Medium · JavaScript
The US Frontend Engineer Market in 2026: A Data-Driven Reality Check (and the Bias That Stops Us Seeing It)
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI