Typing for auth model relationships break when adding token guard
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
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')
This issue has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still need help on this issue
This issue has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still need help on this issue
This issue has been automatically closed because it has been inactive for more than 4 weeks. Please reopen if you still need help on this issue