question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Auth user is not updating on a find

See original GitHub issue

Steps to reproduce

First use the Auth plugin to authenticate to a feathers server. Let the server only return basic user data: Let’s say the server respond with id and displayname fields only. Setup your User model so that instanceDefault add a email property with default value null Later in the app, if you need all user data, using User.get(AUTH_USER_ID) it will populate auth user with his email. But if you use User.find({query:{id:AUTH_USER_ID}}), email won’t get updated. So, to give a small example, this is not working:

const users = (await Users.find({
        query: {
          $select: ['id', 'displayname', 'email'],
          id: {
            $in: userIds
          }
        }
      })).data

whereas this one works (but it’s obviously not optimal)

const users = await Promise.all(userIds.map(async id => {
        return await Users.get(id, {
          query: {
            $select: ['id', 'displayname', 'email']
          }
        })
      }))

Expected behavior

User used in Auth plugin should have his properties updated on a find as it does on a get.

Actual behavior

The find query with the Auth user is like a No-op.

System configuration

NodeJS version: Electron 9.3

Operating System: Archlinux

Browser Version: Electron 9.3

React Native Version: No. Using Quasar 1.14

Module Loader: Webpack 4.44

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Thomas-gitcommented, Feb 4, 2021

I finally found the Bug. And it’s not related to feathers-vuex. I post here the solution because it may affect others. Sometimes my backend server was sending “id” as Number and sometimes as String. It turns out that’s because I use knex with postgresql. And Int8 field, Count and other functions return an int8 : 2^64 max value. As JS max int is 2^53, knex return thoses numbers as String to avoid an overflow. Solution is as easy as doing

const pg = require('pg')

pg.types.setTypeParser(pg.types.builtins.INT8, (value) => {
  return parseInt(value)
})

pg.types.setTypeParser(pg.types.builtins.FLOAT8, (value) => {
  return parseFloat(value)
})

pg.types.setTypeParser(pg.types.builtins.NUMERIC, (value) => {
  return parseFloat(value)
})

But be aware that an overflow become possible… if you have more that 9 Petabytes of entries in a single table!

0reactions
marshallswaincommented, Feb 6, 2021

Oh wow that’s going to be a great resource for somebody in the future, for sure. Thanks for sharing the solution.

On Feb 3, 2021, at 11:16 PM, Thomas-git notifications@github.com wrote:

I finally found the Bug. And it’s not related to feathers-vuex. I post here the solution because it may affect others. Sometimes my backend server was sending “id” as Number and sometimes as String. It turns out that’s because I use knex with postgresql. And Int8 field, Count and other functions return an int8 : 2^64 max value. As JS max int is 2^53, knex return thoses numbers as String to avoid an overflow. Solution is as easy as doing

const pg = require(‘pg’)

pg.types.setTypeParser(pg.types.builtins.INT8, (value) => { return parseInt(value) })

pg.types.setTypeParser(pg.types.builtins.FLOAT8, (value) => { return parseFloat(value) })

pg.types.setTypeParser(pg.types.builtins.NUMERIC, (value) => { return parseFloat(value) }) But be aware that an overflow become possible… if you have more that 9 Petabytes of entries in a single table!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Auth::user() not refreshing after update using POST - Laracasts
I am trying to set a 'nickname' for the user through an AJAX POST request. The request calls on AccountController->setNickname($request).
Read more >
How can I detect changes to Laravel's auth()->user() Object
I think the easiest solution is to assign the field's value to a session variable BEFORE the auth()->user() is updated, but I cannot...
Read more >
Updating user attributes does not update cached user data
Updating user attributes should update the cached user data. Describe the solution you'd like Auth.updateUserAttributes() refreshes the ...
Read more >
Authorization - Laravel - The PHP Framework For Web Artisans
If the action is not authorized or if no user is currently authenticated, Laravel will automatically throw an Illuminate\Auth\Access\AuthorizationException ...
Read more >
Update a user - Supabase
To only send a confirmation link to the user's new email, disable Secure email change in your project's email auth provider settings. User...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found