This commit is contained in:
2023-06-12 20:01:07 +02:00
parent edc42e3750
commit 59b4eb582e
43 changed files with 1799 additions and 245 deletions

View File

@@ -0,0 +1,29 @@
import {
CanActivate,
ExecutionContext,
Injectable,
UnauthorizedException,
} from '@nestjs/common';
import { Observable } from 'rxjs';
@Injectable()
export class BaseAuthGuard implements CanActivate {
canActivate(
context: ExecutionContext,
): boolean | Promise<boolean> | Observable<boolean> {
const request = context.switchToHttp().getRequest();
const exceptedAuthInput = 'Basic YWRtaW46cXdlcnR5';
if (!request.headers || !request.headers.authorization) {
throw new UnauthorizedException([{ message: 'No any auth headers' }]);
} else {
if (request.headers.authorization != exceptedAuthInput) {
throw new UnauthorizedException([
{
message: 'login or password invalid',
},
]);
}
}
return true;
}
}