* refactor: delete unused proxy guard * refactor: roles.guard.ts * refactor: is-org.guard.ts * refactor: permissions.guard.ts * refactor: oauth-client-guard.ts * refactor: is-user-event-type-webhook-guard.ts * refactor: platform-plan.guard.ts * refactor: roles.guard.ts * refactor: cache guard result if canAccess=true * refactor: is-admin-api-enabled.guard.ts * refactor: is-team-in-org.guard.ts * refactor: platform-plan.guard.ts * refactor: is-webhook-in-org.guard.ts * refactor: is-user-in-org.guard.ts * refactor: is-user-webhook-guard.ts * refactor: is-user-in-org-team.guard.ts * refactor: is-membership-in-org.guard.ts * refactor: is-oauth-client-webhook-guard.ts * refactor: is-routing-form-in-team.guard.ts * refactor: is-managed-org-in-manager-org.guard.ts * fill the gaps * refactor: api-auth.strategy.ts * fix: test * implement feedback * fix: tests * fix: refactor * fix: test
15 lines
584 B
TypeScript
15 lines
584 B
TypeScript
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";
|
|
|
|
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);
|
|
if (user || noAuthProvided || !error) {
|
|
return user || null;
|
|
} else {
|
|
throw error;
|
|
}
|
|
}
|
|
}
|