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:
parent
ffdecbd32e
commit
d0901d497b
1 changed files with 6 additions and 7 deletions
|
@ -1,16 +1,15 @@
|
|||
import { ExecutionContext } from "@nestjs/common";
|
||||
import { AuthGuard } from "@nestjs/passport";
|
||||
import { Observable } from "rxjs";
|
||||
|
||||
export class JwtGuard extends AuthGuard("jwt") {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
canActivate(
|
||||
context: ExecutionContext
|
||||
): boolean | Promise<boolean> | Observable<boolean> {
|
||||
return process.env.ALLOW_UNAUTHENTICATED_SHARES == "true"
|
||||
? true
|
||||
: super.canActivate(context);
|
||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||
try {
|
||||
return (await super.canActivate(context)) as boolean;
|
||||
} catch {
|
||||
return process.env.ALLOW_UNAUTHENTICATED_SHARES == "true";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue