Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible wrong type when calling .guard('api').loginAs(someUser) #211

Closed
enxoco opened this issue Nov 3, 2022 · 4 comments
Closed

Possible wrong type when calling .guard('api').loginAs(someUser) #211

enxoco opened this issue Nov 3, 2022 · 4 comments
Assignees
Labels
Type: Question Needs clarification

Comments

@enxoco
Copy link

enxoco commented Nov 3, 2022

Package version

@adonisjs/auth 8.2.1

Node.js and npm version

v16.13.1 and 8.1.2

Sample Code (to reproduce the issue)

test('api token can be used to access authenticated routes', async ({ client }) => {

  const unauthorizedRequest = await client.get('/api/users')
  unauthorizedRequest.assertStatus(401)
  const admin = await User.findByOrFail("username", "admin");

  // Delete all tokens to actually test this.
  await Database.rawQuery(`DELETE FROM api_tokens WHERE user_id = ${admin.id}`)
  const authorizedRequest = await client.get('/api/users').guard('api').loginAs(admin)
  authorizedRequest.assertStatus(200)

})

Issue

Maybe I am doing this wrong but I am trying to write a test to verify that api token authentication is working properly. My first issue is that I get the following type error with the above code:

image

My second issue is that is seems that even if I delete all of the api tokens before attempted to make the request I am still receiving a success response. I would expect that this would fail. Am I not doing this right?

@RomainLanz
Copy link
Member

Hey @enxoco! 👋🏻

Please check #200

@enxoco
Copy link
Author

enxoco commented Nov 3, 2022

@RomainLanz Thanks for the quick reply and I apologize for not doing a thorough search before posting this. I am assuming that I can simply upgrade the auth package to the latest version to resolve this issue? Giving that a shot now.

@RomainLanz
Copy link
Member

Yes, and copy the PR content inside your contracts/auth.ts file where needed.

@thetutlage
Copy link
Member

Closing since not actionable

@thetutlage thetutlage added the Type: Question Needs clarification label Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Question Needs clarification
Projects
None yet
Development

No branches or pull requests

3 participants