adonisjs / auth

Official Authentication package for AdonisJS
https://docs.adonisjs.com/guides/auth/introduction
MIT License
194 stars 65 forks source link

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

Open mauro-arcelles opened 1 week ago

mauro-arcelles commented 1 week ago

Package version

9.2.3

Describe the bug

Im getting the error Cannot assign to read only property 'last_used_at' of 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

thetutlage commented 1 week ago

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

mauro-arcelles commented 1 week ago

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,
    }
}