Closed Foohx closed 2 years ago
Can you share the contracts/auth.ts
file?
Here is the file:
import User from 'App/Models/User'
declare module '@ioc:Adonis/Addons/Auth' {
interface ProvidersList {
user: {
implementation: LucidProviderContract<typeof User>
config: LucidProviderConfig<typeof User>
}
}
interface GuardsList {
api: {
implementation: OATGuardContract<'user', 'api'>
config: OATGuardConfig<'user'>
}
}
}
Its a bug with the default auth contract template. Lemme push a fix
No problem, thank you for your reactivity.
Its a bug with the default auth contract template. Lemme push a fix
Any hint what the problem is?
You will have to make the changes made in this commit manually. https://github.com/adonisjs/auth/commit/946e730cdebcfd277cf69ce29d5be40c80a25ce0
The changes will be inside the contracts/auth.ts
file. New projects will not have this issue
@Foohx was guard or loginAs undefined for you when you run the tests?
@Foohx was guard or loginAs undefined for you when you run the tests?
Don't remember but it was fixed by updating manually the auth contract. Check replies on top :)
@Foohx got it, I fixed the type issue—I also had to use the !
operator for the error to go away. only issue I have is during runtime, the authjs test functions are undefined.
@MANTENN Weird that you have to use the !
operator.
I'm using it without problem like this:
const user = await UserFactory.apply('verified').with('roles').create()
const mock = sinon.mock(ConversationPolicy.prototype)
mock.expects('before').once().resolves(undefined)
mock.expects('viewList').once().resolves(true)
await client.get('/conversations').guard('api').loginAs(user).json({})
mock.verify()
mock.restore()
But I am not in the latest version for the moment. I'm going to update all deps in the next few days and I'll let you know if I encounter the same problem. :)
@Foohx I used the User.find(1) which either returns a user or null hence why I had to use the !
operator.
@Foohx turns out I had NODE_ENV
set to local
so the bindings never were loaded when I ran my tests. I will need to open a PR to create a warning in the CLI.
@Foohx I used the User.find(1) which either returns a user or null hence why I had to use the
!
operator.
Okay, so everything is normal.
In tests, only when chaining
loginAs
toguard
methods, arguments ofloginAs
method are of type never.Package version
@adonisjs/auth:
8.2.1
Node.js and npm version
Node.js:
16.13.0
npm:8.10.0
Sample Code (to reproduce the issue)
Just create a new project with at least
@adonisjs/auth
package, then fill the existing test with the following code :