Access denied when I put two roles on routes using Adonis Acl

Asked

Viewed 94 times

0

Hello, I’m trying to get the administrator and the patient to access some of the routes in my system. But the structure only works when I put only one roll in 'is:(administrador || paciente)' at the end of the code. When I put 'is:administrador' or 'is:paciente' works separately.

I followed what the documentation requires(https://www.npmjs.com/package/adonis-acl#Protect-Routes) but I was unsuccessful.

Route.group(() => {
  Route.resource("/users", "UserController").only(["update"]).validator("User")
  Route.resource("/users", "UserController").only(["show","destroy"]);
  Route.resource("/pacientes", "PacienteController").only(["store", "show", "update", "destroy"]);
  Route.resource("/dentistas", "DentistaController").only(["index"]);
  Route.resource("/consultas", "ConsultaController").only(["store", "destroy"]);
  Route.resource("/especialidades", "EspecialidadeController").only(["index","show"]);
}).middleware(['auth:jwt', 'is:(administrador || paciente)']);

My roles are created correctly and work on other routes

[
  {
    "id": 1,
    "slug": "administrador",
    "name": "Administrador",
    "description": "Realizar qualquer ação",
    "created_at": "2020-10-22 00:03:46",
    "updated_at": "2020-10-22 00:03:46"
  },
  {
    "id": 2,
    "slug": "dentista",
    "name": "Dentista",
    "description": "Visualiza suas proprias consultas",
    "created_at": "2020-10-22 00:03:56",
    "updated_at": "2020-10-22 00:03:56"
  },
  {
    "id": 3,
    "slug": "paciente",
    "name": "Paciente",
    "description": "Gerencia suas informações e consultas",
    "created_at": "2020-10-22 00:04:02",
    "updated_at": "2020-10-22 00:04:02"
  }
]
  • What is the message that appears to you?

1 answer

1


Try to solve using or, in this way:

Route.group(() => {
  Route.resource("/users", "UserController").only(["update"]).validator("User")
  Route.resource("/users", "UserController").only(["show","destroy"]);
  Route.resource("/pacientes", "PacienteController").only(["store", "show", "update", "destroy"]);
  Route.resource("/dentistas", "DentistaController").only(["index"]);
  Route.resource("/consultas", "ConsultaController").only(["store", "destroy"]);
  Route.resource("/especialidades", "EspecialidadeController").only(["index","show"]);
}).middleware(['auth:jwt', 'is:(administrador or paciente)']);
  • 1

    Oops. It worked. Thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.