removing public decorator

This commit is contained in:
2025-08-26 12:56:35 -05:00
parent 04d796da6c
commit 7f86bb383e
3 changed files with 7 additions and 13 deletions

View File

@@ -1,25 +1,14 @@
import { ExecutionContext, Injectable } from '@nestjs/common'; import { ExecutionContext, Injectable } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { AuthGuard as PassportAuthGuard } from '@nestjs/passport'; import { AuthGuard as PassportAuthGuard } from '@nestjs/passport';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { IS_PUBLIC_KEY } from './public.decorator';
@Injectable() @Injectable()
export class AuthGuard extends PassportAuthGuard('azure-ad') { export class AuthGuard extends PassportAuthGuard('azure-ad') {
constructor(private readonly reflector: Reflector) { constructor() {
super(); super();
} }
canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> { canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> {
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
context.getHandler(),
context.getClass()
])
if (isPublic) {
return true;
}
return super.canActivate(context); return super.canActivate(context);
} }
} }

View File

@@ -4,9 +4,11 @@ import {
Headers, Headers,
Query, Query,
StreamableFile, StreamableFile,
UseGuards,
} from '@nestjs/common'; } from '@nestjs/common';
import { UserService } from './user.service'; import { UserService } from './user.service';
import { Client as MsGraphClient } from '@microsoft/microsoft-graph-client'; import { Client as MsGraphClient } from '@microsoft/microsoft-graph-client';
import { AuthGuard } from '../auth/auth.gaurd';
@Controller('user') @Controller('user')
export class UserController { export class UserController {
@@ -15,6 +17,7 @@ export class UserController {
) {} ) {}
@Get('photo') @Get('photo')
@UseGuards(AuthGuard)
async getProfilePhoto(@Headers() headers: any): Promise<StreamableFile> { async getProfilePhoto(@Headers() headers: any): Promise<StreamableFile> {
try { try {
const graphToken: string = await this.userService.getMsGraphAuth( const graphToken: string = await this.userService.getMsGraphAuth(
@@ -37,6 +40,7 @@ export class UserController {
} }
@Get('profile') @Get('profile')
@UseGuards(AuthGuard)
async getUserProfile(@Headers() headers: any): Promise<any> { async getUserProfile(@Headers() headers: any): Promise<any> {
try { try {
const graphToken: string = await this.userService.getMsGraphAuth( const graphToken: string = await this.userService.getMsGraphAuth(
@@ -54,6 +58,7 @@ export class UserController {
} }
@Get('search') @Get('search')
@UseGuards(AuthGuard)
async searchUsers( async searchUsers(
@Headers() headers: any, @Headers() headers: any,
@Query('search') search: any @Query('search') search: any

View File

@@ -1,6 +1,6 @@
{ {
"name": "@noahspan/noahspan-modules", "name": "@noahspan/noahspan-modules",
"version": "1.1.0", "version": "1.1.5",
"description": "", "description": "",
"author": "", "author": "",
"license": "UNLICENSED", "license": "UNLICENSED",