Replies: 1 comment
-
Make sure your middleware flow is correctly stacked. Check this guide: https://adocasts.com/lessons/the-flow-of-middleware |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I am new to Adonis framework, but i have some problems, i have followed the documentation and encounter a problem with the auth middleware.
router
.post('projects', async ({ auth }) => {
console.log(auth.user) // User
console.log(auth.authenticatedViaGuard) // 'api'
console.log(auth.user!.currentAccessToken) // AccessToken
})
.use(
middleware.auth({
guards: ['api']
})
)
Capture d’écran 2024-07-26 à 11 37 38
Type script is advertising me about i can affect string to type never.
how can i achieve that ?
here is my auth middleware
import type { HttpContext } from '@adonisjs/core/http'
import type { NextFn } from '@adonisjs/core/types/http'
import type { Authenticators } from '@adonisjs/auth/types'
/**
/
export default class AuthMiddleware {
/*
*/
redirectTo = '/login'
async handle(
ctx: HttpContext,
next: NextFn,
options: {
guards?: (keyof Authenticators)[]
} = {}
) {
await ctx.auth.authenticateUsing(options.guards, { loginRoute: this.redirectTo })
return next()
}
}
Thanks in advance for your help.
Beta Was this translation helpful? Give feedback.
All reactions