Skip to content

Login method is wasting reads #251

@Revln9

Description

@Revln9

The login method is badly written, everytime you login, it reads the database to check if the user has its own collection or not.

I am talking about this file

authentication.actions.js

Here is how i fixed it for me

login: async ({ commit, dispatch }, firebaseAuthUser) => {
// ##########  ctime is the account creation timestamp. stime is the last login timestamp ########
    const ctime = firebaseAuthUser.metadata.a
    const stime = firebaseAuthUser.metadata.b
    let user

    // ##########  CHECK IF THE USER LOGGED IN FOR THE FIRST TIME ########
    if (ctime === stime){
      user = await createNewUserFromFirebaseAuthUser(firebaseAuthUser)
    } else {
           const authuser = firebaseAuthUser.providerData[0]
            user = {displayName:authuser.displayName , id: firebaseAuthUser.uid, email:authuser.email, photoURL:authuser.photoURL, created:ctime , lastLogin:stime}
    }

    commit('setUser', user)
    dispatch('products/getUserProducts', null, { root: true })
  }

No more useless reads , and it's faster. If someone can put a pull request for this because i didn't fork the repo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions