ferrerojosh / nest-keycloak-connect

keycloak-nodejs-connect module for Nest
MIT License
318 stars 123 forks source link

Issues with the @Public Decorator #168

Closed UderMoreiraDeAssis closed 1 month ago

UderMoreiraDeAssis commented 1 year ago

I am encountering an issue when using the @Public() decorator. It seems that the decorator is not functioning as expected, even when used with @Public(false).

To replicate the problem, please follow these steps:

  1. Access the example in the Nest Keycloak Connect repository: Example on GitHub.
  2. Observe the usage of the @Public() decorator in different routes.
  3. Run the example and check if the routes marked with @Public(false) still do not require authentication, which should not be the case.
  4. I expected the @Public(false) decorator to prevent access without authentication, but this is not happening.

I would like to request assistance in understanding why the decorator is not behaving as expected and how I can correct this in my project.

If necessary, I am willing to contribute to resolving this issue.

ferrerojosh commented 1 year ago

I think you misunderstood the @Public decorator, decorating any function with @Public will effectively make it public. The boolean there to allow a route to have an authenticated user and a public user at the same time. By turning it to false, you also check for authenticated users and in which you can check via request.user or using the @AuthenticatedUser decorator.

ferrerojosh commented 1 month ago

This confusion will be resolved in the next major release. All @Public decorators will make the route available for both users with access token and those without. Its up to the user how to handle them.