Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 83 additions & 41 deletions src/api/api.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
UseInterceptors,
UsePipes,
ValidationPipe,
All,
Req,
} from '@nestjs/common';
import {
SignupResponse,
Expand All @@ -36,6 +38,7 @@ import { Throttle, SkipThrottle} from '@nestjs/throttler';
import { ConfigService } from '@nestjs/config';
import { v4 as uuidv4 } from 'uuid';
import { VerifyJWTDto } from './dto/verify-jwt.dto';
import { Request } from 'express';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const CryptoJS = require('crypto-js');

Expand Down Expand Up @@ -272,21 +275,21 @@ export class ApiController {
);
}

@Get('user/:userId')
async searchUserbyId(
@Param('userId') userId: string,
@Headers('authorization') authHeader,
@Headers('x-application-id') applicationId,
): Promise<UsersResponse> {
const queryString = `(id: ${userId})`; // pass the strict user ID filter
return await this.apiService.fetchUsersByString(
queryString,
undefined,
undefined,
applicationId,
authHeader,
);
}
// @Get('user/:userId')
// async searchUserbyId(
// @Param('userId') userId: string,
// @Headers('authorization') authHeader,
// @Headers('x-application-id') applicationId,
// ): Promise<UsersResponse> {
// const queryString = `(id: ${userId})`; // pass the strict user ID filter
// return await this.apiService.fetchUsersByString(
// queryString,
// undefined,
// undefined,
// applicationId,
// authHeader,
// );
// }

@Post('refresh-token')
async refreshToken(
Expand All @@ -301,33 +304,33 @@ export class ApiController {
);
}

@Patch('/user/:userId/deactivate')
async deactivateUserById(
@Param('userId') userId: string,
@Query('hardDelete') hardDelete = false,
@Headers('authorization') authHeader,
@Headers('x-application-id') applicationId,
): Promise<UsersResponse> {
return await this.apiService.deactivateUserById(
userId,
hardDelete,
applicationId,
authHeader,
);
}
// @Patch('/user/:userId/deactivate')
// async deactivateUserById(
// @Param('userId') userId: string,
// @Query('hardDelete') hardDelete = false,
// @Headers('authorization') authHeader,
// @Headers('x-application-id') applicationId,
// ): Promise<UsersResponse> {
// return await this.apiService.deactivateUserById(
// userId,
// hardDelete,
// applicationId,
// authHeader,
// );
// }

@Patch('/user/:userId/activate')
async activateUserById(
@Param('userId') userId: string,
@Headers('authorization') authHeader,
@Headers('x-application-id') applicationId,
): Promise<UsersResponse> {
return await this.apiService.activateUserById(
userId,
applicationId,
authHeader,
);
}
// @Patch('/user/:userId/activate')
// async activateUserById(
// @Param('userId') userId: string,
// @Headers('authorization') authHeader,
// @Headers('x-application-id') applicationId,
// ): Promise<UsersResponse> {
// return await this.apiService.activateUserById(
// userId,
// applicationId,
// authHeader,
// );
// }

@Post('/changePassword/sendOTP')
async changePasswordOTP(
Expand Down Expand Up @@ -398,4 +401,43 @@ export class ApiController {
): Promise<any> {
return await this.apiService.logout(body.token);
}

@All('*')
async defaultRoute(
@Req() request: Request,
@Headers('authorization') authHeader,
@Headers('x-application-id') applicationId,
@Body() body: any,
@Query() query: any,
@Param() params: any,
): Promise<any> {
const fusionAuthBaseUrl = this.configService.get('FUSIONAUTH_BASE_URL');
const url = new URL(`${fusionAuthBaseUrl}${request.url}`);

// Add query params to URL
if (query) {
Object.keys(query).forEach(key => {
url.searchParams.append(key, query[key]);
});
}

// Add params to URL
if (params) {
Object.keys(params).forEach(key => {
url.searchParams.append(key, params[key]);
});
}

const response = await fetch(url, {
method: request.method,
body: Object.keys(body).length ? JSON.stringify(body) : undefined,
headers: {
'Authorization': authHeader,
'x-application-id': applicationId,
'Content-Type': 'application/json'
}
});

return await response.json();
}
}
7 changes: 5 additions & 2 deletions src/api/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,12 @@ export class ApiService {

async verifyJWT(token:string): Promise<any> {
const { isValidFusionAuthToken, claims} = await this.verifyFusionAuthJWT(token);
let existingUserJWTS:any="[]"

let existingUserJWTS:any = JSON.parse(await this.redis.get(claims.sub));

if(claims?.sub) {
existingUserJWTS = JSON.parse(await this.redis.get(claims.sub));
}

if(!isValidFusionAuthToken){
if(existingUserJWTS.indexOf(token)!=-1){
existingUserJWTS.splice(existingUserJWTS.indexOf(token), 1);
Expand Down
Loading