Skip to content

Commit 6933a25

Browse files
committed
redirecting additional /api requests to fusion auth
1 parent c486dab commit 6933a25

File tree

1 file changed

+83
-41
lines changed

1 file changed

+83
-41
lines changed

src/api/api.controller.ts

Lines changed: 83 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
UseInterceptors,
1313
UsePipes,
1414
ValidationPipe,
15+
All,
16+
Req,
1517
} from '@nestjs/common';
1618
import {
1719
SignupResponse,
@@ -36,6 +38,7 @@ import { Throttle, SkipThrottle} from '@nestjs/throttler';
3638
import { ConfigService } from '@nestjs/config';
3739
import { v4 as uuidv4 } from 'uuid';
3840
import { VerifyJWTDto } from './dto/verify-jwt.dto';
41+
import { Request } from 'express';
3942
// eslint-disable-next-line @typescript-eslint/no-var-requires
4043
const CryptoJS = require('crypto-js');
4144

@@ -272,21 +275,21 @@ export class ApiController {
272275
);
273276
}
274277

275-
@Get('user/:userId')
276-
async searchUserbyId(
277-
@Param('userId') userId: string,
278-
@Headers('authorization') authHeader,
279-
@Headers('x-application-id') applicationId,
280-
): Promise<UsersResponse> {
281-
const queryString = `(id: ${userId})`; // pass the strict user ID filter
282-
return await this.apiService.fetchUsersByString(
283-
queryString,
284-
undefined,
285-
undefined,
286-
applicationId,
287-
authHeader,
288-
);
289-
}
278+
// @Get('user/:userId')
279+
// async searchUserbyId(
280+
// @Param('userId') userId: string,
281+
// @Headers('authorization') authHeader,
282+
// @Headers('x-application-id') applicationId,
283+
// ): Promise<UsersResponse> {
284+
// const queryString = `(id: ${userId})`; // pass the strict user ID filter
285+
// return await this.apiService.fetchUsersByString(
286+
// queryString,
287+
// undefined,
288+
// undefined,
289+
// applicationId,
290+
// authHeader,
291+
// );
292+
// }
290293

291294
@Post('refresh-token')
292295
async refreshToken(
@@ -301,33 +304,33 @@ export class ApiController {
301304
);
302305
}
303306

304-
@Patch('/user/:userId/deactivate')
305-
async deactivateUserById(
306-
@Param('userId') userId: string,
307-
@Query('hardDelete') hardDelete = false,
308-
@Headers('authorization') authHeader,
309-
@Headers('x-application-id') applicationId,
310-
): Promise<UsersResponse> {
311-
return await this.apiService.deactivateUserById(
312-
userId,
313-
hardDelete,
314-
applicationId,
315-
authHeader,
316-
);
317-
}
307+
// @Patch('/user/:userId/deactivate')
308+
// async deactivateUserById(
309+
// @Param('userId') userId: string,
310+
// @Query('hardDelete') hardDelete = false,
311+
// @Headers('authorization') authHeader,
312+
// @Headers('x-application-id') applicationId,
313+
// ): Promise<UsersResponse> {
314+
// return await this.apiService.deactivateUserById(
315+
// userId,
316+
// hardDelete,
317+
// applicationId,
318+
// authHeader,
319+
// );
320+
// }
318321

319-
@Patch('/user/:userId/activate')
320-
async activateUserById(
321-
@Param('userId') userId: string,
322-
@Headers('authorization') authHeader,
323-
@Headers('x-application-id') applicationId,
324-
): Promise<UsersResponse> {
325-
return await this.apiService.activateUserById(
326-
userId,
327-
applicationId,
328-
authHeader,
329-
);
330-
}
322+
// @Patch('/user/:userId/activate')
323+
// async activateUserById(
324+
// @Param('userId') userId: string,
325+
// @Headers('authorization') authHeader,
326+
// @Headers('x-application-id') applicationId,
327+
// ): Promise<UsersResponse> {
328+
// return await this.apiService.activateUserById(
329+
// userId,
330+
// applicationId,
331+
// authHeader,
332+
// );
333+
// }
331334

332335
@Post('/changePassword/sendOTP')
333336
async changePasswordOTP(
@@ -398,4 +401,43 @@ export class ApiController {
398401
): Promise<any> {
399402
return await this.apiService.logout(body.token);
400403
}
404+
405+
@All('*')
406+
async defaultRoute(
407+
@Req() request: Request,
408+
@Headers('authorization') authHeader,
409+
@Headers('x-application-id') applicationId,
410+
@Body() body: any,
411+
@Query() query: any,
412+
@Param() params: any,
413+
): Promise<any> {
414+
const fusionAuthBaseUrl = this.configService.get('FUSIONAUTH_BASE_URL');
415+
const url = new URL(`${fusionAuthBaseUrl}${request.url}`);
416+
417+
// Add query params to URL
418+
if (query) {
419+
Object.keys(query).forEach(key => {
420+
url.searchParams.append(key, query[key]);
421+
});
422+
}
423+
424+
// Add params to URL
425+
if (params) {
426+
Object.keys(params).forEach(key => {
427+
url.searchParams.append(key, params[key]);
428+
});
429+
}
430+
431+
const response = await fetch(url, {
432+
method: request.method,
433+
body: Object.keys(body).length ? JSON.stringify(body) : undefined,
434+
headers: {
435+
'Authorization': authHeader,
436+
'x-application-id': applicationId,
437+
'Content-Type': 'application/json'
438+
}
439+
});
440+
441+
return await response.json();
442+
}
401443
}

0 commit comments

Comments
 (0)