You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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'
/**
Auth middleware is used authenticate HTTP requests and deny
access to unauthenticated users. /
export default class AuthMiddleware {
/*
The URL to redirect to, when authentication fails
*/
redirectTo = '/login'
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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