Firebase Auth Tutorial #6 - Signing Users Out

Net Ninja · Intermediate ·🛠️ AI Tools & Apps ·7y ago

Key Takeaways

Signs users out of a Firebase application using Vue and Firebase Auth

Full Transcript

or rather my friends so at the minute now we have all of our signup form code written so we can sign new users up I'll be it this is not very fun at the minute all we're doing is logging out this credential not really doing anything for the user so there's no point in signing up but all that functionality is gonna come in time and promise you anyway now when we've signed up a new user when we use this method like you said automatically firebase logs us into the application so in their eyes now we're logged in and we get this auth token back okay so that says that we're logged in now then how do we log a user out of the application well it's actually pretty simple we just use a different method so like we use this method over here to sign someone up we just use a different method to log someone out now we have up in the navigation over here this logout oops not that one this logout link so what we need to do is get a reference to that attached a click event to that link and then when a user clicks on it we want to prevent the default action if there isn't it then we want to sign them out using the Sign Out method so then let's do that so if we go to the index and we go to the nav bar at the top we can see this thing right here where is it will log out there so this has an ID of logout so we're going to use that to grab a reference to this anchor tag right here so in auth is let's just neaten this up a little bit I'm gonna delete that console dot log we don't need that anymore but down below what I'm going to do is now a logout method so underneath this will say Const logout is going to be equal to documents doctor query selector and we're going to grab that logout and ID which is the link in the nav bar so log out okay so we have that reference we want to add an event listener to that so log out which is the constant we just created dots add event listener and this event listener it's just going to be a click event so when someone clicks that link at the top and then we're going to find a callback function we'll take in the event object by default and we'll use that inside the error function so that we can prevent the default action and we'll do that by saying e documents default like so invoke that function okay so the next thing we want to do is use a sign out method now again we use the auth object that we declared down here we set up a reference to the auth service and we use all the off methods now on this earth constant so then the way we do this is by grabbing the earth constant then using a method called sign out like so that's all there is to it we don't need to pass in a username or password or an email the user is already logged in and firebase knows this user is logged in so it's gonna take that current user and it's gonna log them out now again this is an asynchronous task it has to communicate with the firebase back-end go out and say look I want to love this user out and then it returns some kind of response to us so because this takes some time to do it returns a promise we can tack on the dot then method and inside here we can fire a callback function this is going to be an error function we don't need to take a response from the server this time all I want to do is just log a little message to the console to say look this user has now logged out later on what we'll be doing is when they log out we're going to be hiding content from them but right now I just want to get the basics of this kind of login or logout authentication flow going so so now we'll just log through the console a little message that says that the user has signed out so console dot log user signed out okay that's all there is to it so then let us now save this and test this out in the browser so we're currently logged in even though we don't see that token right here we're logged in because we recently signed up in the last video and when we signed up it automatically logs us in okay so we're still logged in because of state persistence which means that whenever we refresh the page firebase persists the state of the user was still logged in and now if I log out then we can see this user signed out and that was very quick right so when to the server Sanders out came back and then we logged this message right here user signed out okay so although there's no change to the front ending what we see and what we do and there's no real use to this logging in and logging out at the minute at least we've got the basic flow sorted so that when we click sign we can sign up and when we click log out we're signing the new user out of the application so now we've got those two sorted let us look in the next video and logging in a current user so the court news it is Marriott at the NIT means you don't code at UK we did that in the last video when we signed users up so now we've logged out let's look at how we love that user back in in the very next tutorial

Original Description

Hey gang, in this Firebase auth video we'll see how we can sign users out of our application. VUE & FIREBASE FULL COURSE - https://www.udemy.com/build-web-apps-with-vuejs-firebase/?couponCode=NINJAYT18 ---------------------------------------- 🐱‍💻 🐱‍💻 Course Links: + Course files - https://github.com/iamshaunjp/firebase-auth + VS Code editor - https://code.visualstudio.com/ + Firestore Playlist - + Materialize Playlist - 🤑🤑 Donate + https://www.paypal.me/thenetninja 🎓🎓 Find me on Udemy + https://www.udemy.com/user/47fd83f6-5e4a-4e87-a0f0-519ac51f91b6/
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 Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
2 Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
3 Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
4 GraphQL Tutorial #1 - Introduction to GraphQL
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
5 GraphQL Tutorial #2 - A Birdseye View of GraphQL
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
6 GraphQL Tutorial #3 - Project (stack) Overview
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
7 GraphQL Tutorial #4 - Making Queries (front-end preview)
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
8 GraphQL Tutorial #5 - Express App Setup
GraphQL Tutorial #5 - Express App Setup
Net Ninja
9 GraphQL Tutorial #6 - Setting up GraphQL
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
10 GraphQL Tutorial #7 - GraphQL Schema
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
11 GraphQL Tutorial #8 - Root Query
GraphQL Tutorial #8 - Root Query
Net Ninja
12 GraphQL Tutorial #9 - The Resolve Function
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
13 GraphQL Tutorial #10 - Testing Queries in Graphiql
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
14 GraphQL Tutorial #11 - GraphQL ID Type
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
15 GraphQL Tutorial #12 - Author Type
GraphQL Tutorial #12 - Author Type
Net Ninja
16 GraphQL Tutorial #13 - Type Relations
GraphQL Tutorial #13 - Type Relations
Net Ninja
17 GraphQL Tutorial #14 - GraphQL Lists
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
18 GraphQL Tutorial #15 - More on Root Queries
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
19 GraphQL Tutorial #16 - Connecting to mLab
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
20 GraphQL Tutorial #17 - Mongoose Models
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
21 GraphQL Tutorial #18 - Mutations
GraphQL Tutorial #18 - Mutations
Net Ninja
22 GraphQL Tutorial #19 - More on Mutations
GraphQL Tutorial #19 - More on Mutations
Net Ninja
23 GraphQL Tutorial #20 - Updating the Resolve Functions
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
24 GraphQL Tutorial #21 - GraphQL NonNull
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
25 GraphQL Tutorial #22 - Adding a Front-end
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
26 GraphQL Tutorial #23 - Create React App
GraphQL Tutorial #23 - Create React App
Net Ninja
27 GraphQL Tutorial #24 - Book List Component
GraphQL Tutorial #24 - Book List Component
Net Ninja
28 GraphQL Tutorial #25 - Apollo Client Setup
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
29 GraphQL Tutorial #26 - Making Queries from React
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
30 GraphQL Tutorial #27 - Rendering Data in a Component
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
31 GraphQL Tutorial #28 - Add Book Component
GraphQL Tutorial #28 - Add Book Component
Net Ninja
32 GraphQL Tutorial #29 - External Query File
GraphQL Tutorial #29 - External Query File
Net Ninja
33 GraphQL Tutorial #30 - Updating Component State
GraphQL Tutorial #30 - Updating Component State
Net Ninja
34 GraphQL Tutorial #31 - Composing Queries
GraphQL Tutorial #31 - Composing Queries
Net Ninja
35 GraphQL Tutorial #32 - query variables
GraphQL Tutorial #32 - query variables
Net Ninja
36 GraphQL Tutorial #33 - Re-fetching Queries
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
37 GraphQL Tutorial #34 - Book Details Component
GraphQL Tutorial #34 - Book Details Component
Net Ninja
38 GraphQL Tutorial #36 - Styling the App
GraphQL Tutorial #36 - Styling the App
Net Ninja
39 GraphQL Tutorial #35 - Making a Single Query
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
40 Build Apps with Vue & Firebase - Udemy Course
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
41 Updated Vue & Firebase Course (Udemy)
Updated Vue & Firebase Course (Udemy)
Net Ninja
42 Vue & Firebase Real-time Chat (Preview) #1 - Intro
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
43 Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
44 Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
45 Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
46 Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
47 Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
48 Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
49 Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
50 Object Oriented JavaScript Tutorial #1 - Introduction
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
51 Object Oriented JavaScript Tutorial #2 - Object Literals
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
52 Object Oriented JavaScript Tutorial #3 - Updating Properties
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
53 Object Oriented JavaScript Tutorial #4 - Classes
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
54 Object Oriented JavaScript Tutorial #5  - Class Constructors
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
55 Object Oriented JavaScript Tutorial #6 - Class Methods
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
56 Object Oriented JavaScript Tutorial #7 - Method Chaining
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
57 Object Oriented JavaScript Tutorial #8 - Class Inheritance
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
58 Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
59 Object Oriented JavaScript Tutorial #10 - Prototype
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
60 Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja

Related AI Lessons

Up next
I Asked ChatGPT to Apply to 500 Jobs (8 Interviews in 48 Hours)
Sabrina Ramonov 🍄
Watch →