fix: OptionalApiAuthGuard when only client id is provided (#23783)

This commit is contained in:
Morgan authored and GitHub committed 2025-09-12 12:16:52 +03:00
1 parent a977fb4970
commit 74288b0ecb
2 files changed
+18 -1

No files matched your search

@@ -1,10 +1,19 @@
import { ApiAuthGuard } from "@/modules/auth/guards/api-auth/api-auth.guard";
import { NO_AUTH_PROVIDED_MESSAGE } from "@/modules/auth/strategies/api-auth/api-auth.strategy";
import {
NO_AUTH_PROVIDED_MESSAGE,
ONLY_CLIENT_ID_PROVIDED_MESSAGE,
} from "@/modules/auth/strategies/api-auth/api-auth.strategy";
export class OptionalApiAuthGuard extends ApiAuthGuard {
handleRequest(error: Error, user: any) {
// note(Lauris): optional means that auth is not required but if it is invalid then still throw error.
const noAuthProvided = error && error.message.includes(NO_AUTH_PROVIDED_MESSAGE);
const onlyClientIdProvided = error && error.message.includes(ONLY_CLIENT_ID_PROVIDED_MESSAGE);
if (onlyClientIdProvided) {
return null;
}
if (user || noAuthProvided || !error) {
return user || null;
} else {