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

Typing for auth model relationships break when adding token guard #246

Open
jarle opened this issue Jul 28, 2024 · 1 comment
Open

Typing for auth model relationships break when adding token guard #246

jarle opened this issue Jul 28, 2024 · 1 comment
Assignees
Labels
Type: Bug The issue has indentified a bug

Comments

@jarle
Copy link

jarle commented Jul 28, 2024

Package version

9.2.3

Describe the bug

When adding the token guard to my project I got typescript errors in existing code when trying to load relationships on the auth model.

router.get('/foo', async ({ auth }) => {
  // here the signature of the load method is of type _any_
  await auth.user?.load('post')
  // this gives type error (Argument of type '"post"' is not assignable to parameter of type 'undefined'.ts(2345))
  await auth.user?.related('post').query().first()
  return null
})

Reproduction repo

https://github.com/jarle/adonis-auth-issue

@thetutlage thetutlage self-assigned this Jul 30, 2024
@thetutlage thetutlage added the Type: Bug The issue has indentified a bug label Jul 30, 2024
@thetutlage
Copy link
Member

Yeah, that is indeed an issue with the types. The immediate way to fix it to use a specific guard before accessing the user property. For example:

auth.use('api').user?.related('posts')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug The issue has indentified a bug
Projects
None yet
Development

No branches or pull requests

2 participants