Vuex 4 & Firebase Auth Tutorial #8 - Login Action
Skills:
Tool Use & Function Calling70%
Key Takeaways
This video tutorial covers creating a login action using Vuex 4 and Firebase Auth, including setting up the login function, handling errors, and updating the user state.
Full Transcript
all right then so now we have our sign up action right here when a user signs up and when a user signs up firebase sends us back the user on the response so we commit that mutation set user and pass in that user so that we update the state right here to be that new user who's just signed up and that happens so now when they sign up our global state becomes that new user and then we can access that user wherever we want in the application now what i'd like to do is move on to the next action which is going to be the login action and this is actually going to be very similar to this one right here so first of all we need to import another function up here from firebase and this one is called sign in with email and password so sign in with email and password like so all right so now we have that i'm going to create a new function down here so comma and then async login like so we take in the context object and also we want the email and password on the payload so let's destructure that like so and then the inside of the function is going to be almost identical to this one so what i'm going to do is copy all this and paste it down here so first of all let's change this to login action and then over here we still get a response the function this time though is called sign in with email and password we're still passing the auth object as the first argument then the email then the password then we're logging out the response here we don't need that and in fact we don't need it up here as well let's get rid of that but if we have a response then we commit a mutation set user and we pass in the user object on that response object so again when we sign in and we commit this mutation right here we're saying okay update the user state to be that new user we pass in as a payload all right so that's when they sign in all right so then we'll say right here could not complete login like so and that's pretty much it for this action so now all we need to do is use the action inside the login component so again a lot of this is going to be very similar to this signup code right here so what i'm going to do is just copy all of this from error down here like so copy all of that and come over here and replace this thing so up here paste it in so we have the error now we have the store and the router and in fact we need to import those so let's do that as well import and we want the use store function from vue x then we also want use router as well so import use router and that comes from view router like so okay so handle submit is an async function we try this where we dispatch an action this time it needs to be the login action we're still passing the email and password values which are these refs and then if it's a success we push them to the home page if not we catch the error and we update our error ref to be the error message we need to also return the error right here and then we can output the error up here as well so i'll do another div with a v hyphen if and we set that equal to error so only if there's an error where we try to output it so in curly braces error like so then close off the div alright so that my friends is pretty much it so when they submit this form now we should be trying to dispatch the login action which is going to try to sign them up or rather sign them in sorry with this function and then when that's complete we get a response object back we commit a mutation to update our state with that user that's logged in all right okay so let's now save all this and give it a whirl all right so we already created that user mario at netninja.dev let's try logging in with that user so mario netninja dot dev and then test one two three in fact we'll just do test one two three which is the incorrect password because i want to show you the error right here so log in and we can see firebase error wrong password now you might not want to show that error to your user you could write a custom error instead but for the sake of this tutorial it's fine we know it's the wrong password so now i can add on forum five login then it should redirect us to the home page and we can see user state changed and this is the new user state in the store now and we can see it right here alright awesome so now we can sign in and now we can log in and when we do those things we're updating our store state to reflect that user who was either signed up or logged in next up we need to handle what happens when we try to log out
Original Description
Hey gang, in this lesson we'll create a login action to log the user in & then update our user state.
🔥🔥 Get the full course now on Net Ninja Pro 👉 https://netninja.dev/p/vuex-with-firebase-auth
🐱💻 Access the course files on GitHub:
https://github.com/iamshaunjp/Vuex-4-Firebase-Auth
🐱💻 Starter Project:
https://github.com/iamshaunjp/Vuex-4-Firebase-Auth/tree/lesson-1
🐱💻 Vue 3 & Firebase Complete Course:
On Net Ninja Pro - https://netninja.dev/p/build-websites-with-vue-3-firebase
On Udemy - https://thenetninja.co.uk/udemy/vue-and-firebase
🐱💻 Vue 3 Basics Course:
On YouTube - https://www.youtube.com/watch?v=YrxBCBibVo0&list=PL4cUxeGkcC9hYYGbV60Vq3IXYNfDk8At1
🐱💻 Getting Started with Firebase Course:
On Net Ninja Pro - https://netninja.dev/p/getting-started-with-firebase-9
On YouTube - https://www.youtube.com/watch?v=9zdvmgGsww0&list=PL4cUxeGkcC9jERUGvbudErNCeSZHWUVlb
🐱👤 My Premium Udemy courses:
https://thenetninja.co.uk/udemy/react-and-firebase
https://thenetninja.co.uk/udemy/vue-and-firebase
https://thenetninja.co.uk/udemy/modern-javascript
https://thenetninja.co.uk/udemy/d3-and-firebase
🐱👤 Get access to all other premium courses on Net Ninja Pro:
https://netninja.dev/
🐱💻 My Social Links:
Facebook - https://www.facebook.com/thenetninjauk
Twitter - https://twitter.com/thenetninjauk
Instagram - https://www.instagram.com/thenetninja/
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: Tool Use & Function Calling
View skill →Related Reads
📰
📰
📰
📰
The 5 Levels of Front End Engineering (And Where Most Developers Get Stuck)
Medium · Programming
Browser-Based PDF Editing with Vue 3 and pdf-lib
Dev.to · sunshey
Say Goodbye To Electron?
Medium · Programming
Why Vanilla JS?
In the article below, I am sharing my story of building SaaS product in vanilla js and explaining why I decided to go with this approach.
https://guseyn.com/html/posts/why-vanilla-js.html
Dev.to · Guseyn Ismayylov
🎓
Tutor Explanation
DeepCamp AI