Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorsulcer committed Dec 8, 2023
1 parent 68c6e8a commit f44cc1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class AuthController {

@HttpCode(HttpStatus.OK)
@Post('authenticate')
validate(@Body() token: Record<string, any>) {
return this.authService.validate();
validate(@Body() token: string) {
return this.authService.validate(token);
}
}
17 changes: 12 additions & 5 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { HttpService } from '@nestjs/axios';
import process from 'process';

@Injectable()
export class AuthService {
constructor() {}
constructor(private readonly httpService: HttpService) {}

async validate(): Promise<any> {
//TODO: get token from auth microservice
const token = 'token';
if (!token) {
async validate(token: string): Promise<any> {
const authMicroservice = process.env.AUTH_SERVICE;

try {
const { data: response } = await this.httpService.axiosRef.get(
`${authMicroservice}/auth/verify`,
{ headers: { Authorization: `${token}` } },
);
} catch (e) {
throw new UnauthorizedException();
}
return true;
Expand Down

0 comments on commit f44cc1b

Please sign in to comment.