adonisjs/auth

Wrong token prefix is being generated

Xorbert opened this issue · 0 comments

Prerequisites

Have Postgres Database

The following code
const token = await auth.use('api').attempt(email, password, {
expiresIn: lifetime,
})
token will have an base64 encoded "[object Object]" instead the expected integerish ID from lucid.
The Token will look like this: W29iamVjdCBPYmplY3Rd.3hPYyUdIfed9LEvniRRfRWP4Wrh8roANdyQaofcbz8sGWtl6V1IWFY9bJToi
Where the first part is like "W29iamVjdCBPYmplY3Rd" == base64("[object Object]")

This happens, because Database.js appears to get an Object looking like {id: 123} instead 123, as before Lucid v17
on line 116
const [persistedToken] = await client.table(this.config.table).insert(payload).returning('id');

When downgrading to lucid 16.3 everything works fine, I just did not have the resources to debug further, and wrote you a ticket.

Package version

"^8.0.11"

Node.js and npm version

node v17.4.0
npm 8.3.1

Sample Code (to reproduce the issue)

See prerequisites