Closed Mederick-ROBERT closed 1 month ago
Hey @Mederick-ROBERT! 👋🏻
Can you please share your User
class?
Yes of course, I didn't change anything on this after the install :
With the acces token guard :
import { DateTime } from 'luxon'
import hash from '@adonisjs/core/services/hash'
import { compose } from '@adonisjs/core/helpers'
import { BaseModel, column } from '@adonisjs/lucid/orm'
import { withAuthFinder } from '@adonisjs/auth/mixins/lucid'
import { DbAccessTokensProvider } from '@adonisjs/auth/access_tokens'
const AuthFinder = withAuthFinder(() => hash.use('scrypt'), {
uids: ['email'],
passwordColumnName: 'password',
})
export default class User extends compose(BaseModel, AuthFinder) {
@column({ isPrimary: true })
declare id: number
@column()
declare fullName: string | null
@column()
declare email: string
@column({ serializeAs: null })
declare password: string
@column.dateTime({ autoCreate: true })
declare createdAt: DateTime
@column.dateTime({ autoCreate: true, autoUpdate: true })
declare updatedAt: DateTime | null
static accessTokens = DbAccessTokensProvider.forModel(User)
}
without the guard :
import { DateTime } from 'luxon'
import { BaseModel, column } from '@adonisjs/lucid/orm'
export default class User extends BaseModel {
@column({ isPrimary: true })
declare id: number
@column()
declare fullName: string | null
@column()
declare email: string
@column({ serializeAs: null })
declare password: string
@column.dateTime({ autoCreate: true })
declare createdAt: DateTime
@column.dateTime({ autoCreate: true, autoUpdate: true })
declare updatedAt: DateTime | null
}
I have the same issue with a similar User model. Only thing I changed is the prop name email
to username
in model and migration files. Package version is 21.2.0. Created project with adonis api starter project.
I got the same issue with db:seed. I wonder why it select from "user_with_user_finders" where it doesn't event exists. I updated @adonisjs/lucid to 21.3.0 and @swc/core to 1.7.35
❯ completed database/seeders/main/index_seeder
"postgres" User (3.37 ms) SELECT * FROM "user_with_user_finders" WHERE "username" = ? LIMIT ? FOR UPDATE [ 'admin', 1 ]
❯ error database/seeders/main/user_seeder
select * from "user_with_user_finders" where "username" = $1 limit $2 for update - relation "user_with_user_finders" does not exist
// my seed file
export default class UserSeeder extends BaseSeeder {
async run() {
await User.updateOrCreate({
username: 'admin',
}, {
password: 'password'
});
}
}
// my model
import type { DateTime } from 'luxon';
import { DbAccessTokensProvider } from '@adonisjs/auth/access_tokens';
import { withAuthFinder } from '@adonisjs/auth/mixins/lucid';
import { compose } from '@adonisjs/core/helpers';
import hash from '@adonisjs/core/services/hash';
import { BaseModel, column } from '@adonisjs/lucid/orm';
const AuthFinder = withAuthFinder(() => hash.use('scrypt'), {
uids: ['username'],
passwordColumnName: 'password',
});
export default class User extends compose(BaseModel, AuthFinder) {
@column({ isPrimary: true })
declare id: number;
@column()
declare username: string;
@column()
declare password: string;
@column()
declare isActive: boolean;
@column.dateTime({ autoCreate: true })
declare createdAt: DateTime;
@column.dateTime({ autoCreate: true, autoUpdate: true })
declare updatedAt: DateTime;
static accessTokens = DbAccessTokensProvider.forModel(User, {
expiresIn: '1h',
});
}
Can you try to downgrade @swc/core
to 1.7.26
?
@RomainLanz yes it works.
Can you try to downgrade
@swc/core
to1.7.26
?
Downgrade to this version works. I had to manually replace in my lock file for some reason, but thats okay. ^_^
Future discussion will happen here. https://github.com/adonisjs/core/issues/4759
Package version
21.2.0
Describe the bug
I started a new project with the API Starter Kit and access_tokens guard + a Postgres db. I connect the db in
.env
file, realised migrations with success. After I create a new seeder for create a new user, I have this error :The seeder :
I test with the same things but without the
access token
guard and I have this new error :After that, I create a GET route with a json response for getting all users, and I get this error :
I don't know if it's a bug, or if I configured my project incorrectly
Reproduction repo
No response