Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login method is wasting reads #251

Open
Revln9 opened this issue Mar 2, 2021 · 0 comments
Open

Login method is wasting reads #251

Revln9 opened this issue Mar 2, 2021 · 0 comments

Comments

@Revln9
Copy link

Revln9 commented Mar 2, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant