Closed andymel123 closed 6 months ago
I am still interested in getting an answer here :)
You can pass a boolean of false in the @Public
decorator.
@Public(false)
async create(@AuthenticatedUser() jwtData: any): Promise<...> {
const username = jwtData == null ? 'anonymous' : jwtData...;
...
}
My (simplified) use case: I have an endpoint that can be used both with and without being logged in. If the user is not logged in, I use "anonymous" as username otherwise I want to retrieve the username from the token.
Example:
Is there a "nest-keycloak-connect way" of getting the JWT data in public endpoints? In the above construct (@ Public and @AuthenticatedUser() combined) the user is always undefined as the auth.guard is skipped.
I could read and parse the token myself but it would be more consistent to use nest-keycloak-connect to do it.
Any recommendation to fulfill the use case without re-writing the code? Seems like the specific logic in the library is not exported/public.