auth icon indicating copy to clipboard operation
auth copied to clipboard

Cannot assign to read only property 'last_used_at' of object '#<Object>'

Open mauro-arcelles opened this issue 1 year ago • 2 comments

Package version

9.2.3

Describe the bug

Im getting the error Cannot assign to read only property 'last_used_at' of object '#<Object>' when trying to use the access token on Bearer auth for an api endpoint Im using:

  • API Starter kit
  • LibSQL with turso url
  • Access tokens auth
config/database.ts
import env from "#start/env"
import { defineConfig } from "@adonisjs/lucid"

const dbUrl = env.get("TURSO_DB_URL")

const dbConfig = defineConfig({
  connection: "libsql",
  connections: {
    libsql: {
      client: "libsql",
      connection: {
        filename: dbUrl,
      },
      pool: {
        min: 0,
        idleTimeoutMillis: 5 * 1000,
      },
      useNullAsDefault: true,
      migrations: {
        naturalSort: true,
        paths: ["database/migrations"],
      },
    },
  },
})

export default dbConfig

The error is thrown in line 313 in verify method in: https://github.com/adonisjs/auth/blob/main/modules/access_tokens_guard/token_providers/db.ts

Reproduction repo

https://github.com/mauro-arcelles/adonis-auth-bug

mauro-arcelles avatar Oct 08 '24 17:10 mauro-arcelles

Can you please share where exactly in your codebase you face this error?

thetutlage avatar Oct 08 '24 19:10 thetutlage

In the reproduction repo, when I try to fetch "/me" endpoint from AuthController's "me" method, when doing auth.authenticate()

async me({ auth }: HttpContext) {
    await auth.authenticate()

    return {
      user: auth.user,
    }
}

mauro-arcelles avatar Oct 08 '24 19:10 mauro-arcelles

I have the same problem but it happens when assign to my route group an auth middleware: router .group(() => { router.get('users', [UsersController, 'index']) router.get('users/filters', [UsersController, 'filters']) router.get('users/:id', [UsersController, 'show']) router.post('users', [UsersController, 'store']) router.put('users/:id', [UsersController, 'update']).where('id', /^[0-9]+$/) router.patch('users/:id', [UsersController, 'replace']).where('id', /^[0-9]+$/) router.delete('users/:id', [UsersController, 'destroy']).where('id', /^[0-9]+$/) }) .prefix('api/v1') .middleware(middleware.auth({ guards: ['api'] }))

MarsaColombo avatar Dec 22 '24 14:12 MarsaColombo

The errors is on the line 22 `import type { HttpContext } from '@adonisjs/core/http' import type { NextFn } from '@adonisjs/core/types/http' import type { Authenticators } from '@adonisjs/auth/types'

/**

  • Auth middleware is used authenticate HTTP requests and deny
  • access to unauthenticated users. / export default class AuthMiddleware { /*
    • The URL to redirect to, when authentication fails */ redirectTo = '/login'

async handle( ctx: HttpContext, next: NextFn, options: { guards?: (keyof Authenticators)[] } = {} ) { await ctx.auth.authenticateUsing(options.guards, { loginRoute: this.redirectTo }) <-Here return next() } } ` And seems to refer to tha AccessToken class in the https://github.com/adonisjs/auth/blob/main/modules/access_tokens_guard/token_providers/db.ts which contains the lastUsedAt property

MarsaColombo avatar Dec 22 '24 14:12 MarsaColombo

This issue has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still need help on this issue

github-actions[bot] avatar Jan 18 '25 01:01 github-actions[bot]

This issue has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still need help on this issue

github-actions[bot] avatar Feb 08 '25 01:02 github-actions[bot]

This issue has been automatically closed because it has been inactive for more than 4 weeks. Please reopen if you still need help on this issue

github-actions[bot] avatar Feb 13 '25 01:02 github-actions[bot]