0
Fork 0
mirror of https://github.com/stonith404/pingvin-share.git synced 2025-01-29 01:28:59 -05:00

ix: jwt guard when unauthenticated shares are allowed

This commit is contained in:
Elias Schneider 2022-10-29 22:48:00 +02:00
parent ffdecbd32e
commit d0901d497b

View file

@ -1,16 +1,15 @@
import { ExecutionContext } from "@nestjs/common"; import { ExecutionContext } from "@nestjs/common";
import { AuthGuard } from "@nestjs/passport"; import { AuthGuard } from "@nestjs/passport";
import { Observable } from "rxjs";
export class JwtGuard extends AuthGuard("jwt") { export class JwtGuard extends AuthGuard("jwt") {
constructor() { constructor() {
super(); super();
} }
canActivate( async canActivate(context: ExecutionContext): Promise<boolean> {
context: ExecutionContext try {
): boolean | Promise<boolean> | Observable<boolean> { return (await super.canActivate(context)) as boolean;
return process.env.ALLOW_UNAUTHENTICATED_SHARES == "true" } catch {
? true return process.env.ALLOW_UNAUTHENTICATED_SHARES == "true";
: super.canActivate(context); }
} }
} }