Create custom middleware with auth

#1

Why does not the auth object work in my middleware? I added it to ‘kernel.js’ as ‘authisadmin’ and called the middleware (‘authisadmin’) on the route.

'use strict'

class AuthIsAdmin {

    async handle ({ auth }, next) {

        let user = await auth.getUser()

        if (!user.is_admin) {
            console.log('not is admin')
            return 
        }
        
        await next()
        
    }
}

module.exports = AuthIsAdmin

0 Likes