'Mongo Auth Provider doesn't inject user object in routing context after authentification in vert.x 4.2.5

i'm using vert.x 4.2.5, and mongodb as auth provider.

the problem that even after logging in successfully, the user still can't access to the private routes, and i can't find the user object injected in routing context

my api :

Router apiAuth = Router.router(vertx);

SessionStore store = LocalSessionStore.create(vertx);
SessionHandler sessionHandler = SessionHandler.create(store);

apiAuth.route().handler(sessionHandler);
apiAuth.route().handler(BodyHandler.create());

AuthenticationHandler basicAuthHandler = BasicAuthHandler.create(authenticationProvider);

apiAuth.post("/login").handler(this::login);
apiAuth.get("/checkLogin").handler(basicAuthHandler);
apiAuth.get("/checkLogin").handler(this::checkLogin);

Login method :

  private void login(RoutingContext routingContext) {
    JsonObject body = routingContext.getBodyAsJson();
    JsonObject authInfo =
        new JsonObject()
            .put("username", body.getString("username"))
            .put("password", body.getString("password"));
    authenticationProvider
      .authenticate(authInfo).onSuccess(user -> {
        routingContext
          .response()
          .setStatusCode(200)
          .putHeader("Content-Type", "application/json")
          .end(
            new JsonObject()
              .put("success", true)
              .encode());
      });
  }

checkLogin method :

  private void checkLogin(RoutingContext routingContext) {
    routingContext.response().setStatusCode(200).end(new JsonObject().put("authenticated", true).encode());
  }



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source