I encountered an issue while configuring authentication guards in my AdonisJS application. I have defined the authConfig object in my config/auth.ts file as follows:
config/auth.ts
const authConfig = defineConfig({ default: 'api', guards: { api: tokensGuard({ provider: tokensUserProvider({ tokens: 'accessTokens', model: () => import('#models/user') }), }), }, })
In the start/routes.ts file, I'm trying to authenticate using the api guard as follows:
router.post('projects', async ({ auth, response }) => { // Authenticate using the default guard const user = await auth.authenticateUsing('api' as any); // from your docs // const user = await auth.authenticate() return response.send({ message: 'Project created', user: user }) })
Package version
^6.8.0
Describe the bug
I encountered an issue while configuring authentication guards in my AdonisJS application. I have defined the authConfig object in my config/auth.ts file as follows: config/auth.ts
const authConfig = defineConfig({ default: 'api', guards: { api: tokensGuard({ provider: tokensUserProvider({ tokens: 'accessTokens', model: () => import('#models/user') }), }), }, })
In the start/routes.ts file, I'm trying to authenticate using the api guard as follows:
router.post('projects', async ({ auth, response }) => { // Authenticate using the default guard const user = await auth.authenticateUsing('api' as any); // from your docs // const user = await auth.authenticate() return response.send({ message: 'Project created', user: user }) })
The errors:
The issue is here (red section)
![image](https://github.com/adonisjs/core/assets/132663408/7c38dfd7-ed4d-4f50-b1bb-22de2fb86ea8)
Reproduction repo
No response