Skip to content

Commit 109462f

Browse files
authored
chore: api Logging#setUser expects user.id as string instead of number (#2233)
Motivation: * this way `Logging#setUser` can accomodate user ids that correspond to bigints * avoid this mistake web3-storage/web3.storage#2040 Related * I noticed that the db-types user definition has `id: number`. I wonder if it should change to `bigint` or `text` (and underlying queries will need to change). https://github.com/nftstorage/nft.storage/blob/6fcd38923506965012505473b57afde2ce22973e/packages/api/src/utils/db-types.d.ts#L1188 * nft.storage prod counter isn't at risk of bumping into this soon, but it is a bigint underneath so it could happen.
1 parent 203f7c1 commit 109462f

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

packages/api/src/utils/auth.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export async function validate(event, { log, db, ucanService }, options) {
5252
}
5353
const user = await db.getUser(root.audience())
5454
if (user) {
55-
log.setUser({ id: user.id })
55+
log.setUser({ id: user.id.toString() })
5656
return {
5757
user: filterDeletedKeys(user),
5858
db,
@@ -83,7 +83,7 @@ export async function validate(event, { log, db, ucanService }, options) {
8383
}
8484

8585
log.setUser({
86-
id: user.id,
86+
id: user.id.toString(),
8787
})
8888
return {
8989
user: filterDeletedKeys(user),
@@ -105,7 +105,7 @@ export async function validate(event, { log, db, ucanService }, options) {
105105
const user = await db.getUser(claim.iss)
106106
if (user) {
107107
log.setUser({
108-
id: user.id,
108+
id: user.id.toString(),
109109
})
110110

111111
return {

packages/api/src/utils/logs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class Logging {
4646
}
4747
this.metadata = {
4848
user: {
49-
id: 0,
49+
id: '0',
5050
},
5151
request: {
5252
url: request.url,
@@ -68,10 +68,10 @@ export class Logging {
6868
* Set user
6969
*
7070
* @param {Object} user
71-
* @param {number} [user.id]
71+
* @param {string} user.id
7272
*/
7373
setUser(user) {
74-
this.metadata.user.id = user.id || 0
74+
this.metadata.user.id = user.id
7575
this.opts.sentry.setUser({
7676
id: `${user.id}`,
7777
})

0 commit comments

Comments
 (0)