How to get current logged in user in validator (using route vailidator)

Hi guys, i’m new with adonisjs.
Currently, i want to get current logged in user in my validator (because i want to change rules based on users is logged in or not). Can you guys tell me how to do this? Thanks

Hi!

You can take a look into this
https://adonisjs.com/docs/4.1/validator#_request_context

You can perhaps access this.ctx.auth in validator

1 Like

@McSneaky Thanks for your reply.

I’ve already read this. But to get current logged in user, it should be used with await. But rules is getter and can not be async function.

As McSneaky said:

get rules() {
    const user = this.ctx.auth.user

    return {} 
}
1 Like