uawdijnntqw1x1x1
IP : 216.73.217.47
Hostname : srv913213
Kernel : Linux srv913213 5.15.0-179-generic #189-Ubuntu SMP Tue May 5 18:20:56 UTC 2026 x86_64
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
OS : Linux
PATH:
/
var
/
snap
/
..
/
.
/
lib
/
..
/
www
/
talentgenesis_admin_backend
/
src
/
guards
/
auth.guard.ts
/
/
import { CanActivate, ExecutionContext, Injectable, UnauthorizedException } from '@nestjs/common' import { Reflector } from '@nestjs/core' import { InjectRepository } from '@nestjs/typeorm'; import * as jwt from 'jsonwebtoken' import { aclPermission } from 'src/admin/permission/entities/permission.entity'; import { PermissionService } from 'src/admin/permission/permission.service'; import { Users } from 'src/admin/user/entities/user.entity'; import { CryptoService } from 'src/aesEncrypt/aes-service'; import { Customers } from 'src/mobile/auth/entities/auth.entity'; import { Repository } from 'typeorm'; import { checkMobileUrl, checkAdminUrl, skipEndpoint, viewForUpdate, checkForUpdate, listPermission } from 'src/permissionUrls'; interface JWTPayload { platform: string, user_id: number, user_email: string, user_name: string, role_id: number, role_name: string, iat: number; exp: number; permission: object } @Injectable() export class AuthGuard implements CanActivate { constructor( private readonly reflector: Reflector, private cryptoService: CryptoService, private readonly permissionService: PermissionService, @InjectRepository(aclPermission) private permissionRepository: Repository<aclPermission>, @InjectRepository(Users) private userRepository: Repository<Users>, // @InjectRepository(CurrentAccountNetbanking) private currentAccountNetbanking: Repository<CurrentAccountNetbanking>, // @InjectRepository(SavingsAccount) private savingsAccountNetbanking: Repository<SavingsAccount>, @InjectRepository(Customers) private customerRepository: Repository<Customers>, ) { } async canActivate(context: ExecutionContext) { // const validOrigin=['http://localhost:3009','http://[::1]:3000','http://192.168.1.29:3000','http://13.127.167.195:3000',"http://localhost:4000",undefined] const roles = this.reflector.get<string[]>('roles', context.getHandler()); const request = context.switchToHttp().getRequest(); const token = request?.headers?.authorization?.split("Bearer ")[1] const checkOrigin = request?.headers?.['origin'] // if(!validOrigin.includes(checkOrigin) ){ // return false // } if (!token) throw new UnauthorizedException; // try { const tokenDecrypt = await this.cryptoService.newdecrypt(token) console.log(tokenDecrypt, "tokenDecrypttokenDecrypttokenDecrypttokenDecrypt") try { const payload = await jwt.verify(tokenDecrypt, process.env.JSON_TOKEN_KEY) as JWTPayload request['user'] = payload; console.log(payload) if (payload.platform === 'mobile') { // return true // const checkMobileUrl = ['paymentgateway','file_upload', 'mobile_account_delete', 'mobile_logout', 'mobile_sessionout', 'mobile_helpSupport', 'mobile_rental_categories', 'mobile_transaction_list', 'mobile_transaction_view', 'mobile_profile_image', 'mobile_profile_view', 'mobile_upi', 'mobile_account', 'mobile_landlord_category_view', 'mobile_customer_landlord_view', 'mobile_landlord_payagain', 'mobile_landlord_payagain_update', 'mobile_transaction_list_category', 'mobile_transaction_view_category', 'mobile_landlord_transaction_list', 'mobile_landlord_upcoming_trans_list', 'mobile_landlord_upcomingtrans_cat_list', 'mobile_landlord_upcomingtrans_allcat_list', 'mobile_landlord_trans_create', 'mobile_landlord_trans_list_filter', 'mobile_updatefcmtoken', 'mobile_markallread', 'mobile_notification_list', 'read_unread','payment_gateway_mobile'] const getPAth = roles[0] if (!checkMobileUrl.includes(getPAth)) { throw new UnauthorizedException; } const customer = await this.customerRepository.findOne({ where: { customerId: payload.user_id, }, }); if (![null, undefined, ''].includes(customer.refreshToken) && token == customer.refreshToken) { return true } else { throw new UnauthorizedException; } } else if(payload.platform === 'admin'){ return true }else { const getPAth = roles[0] if (!checkAdminUrl.includes(getPAth)) { console.log("role errorrrr") throw new UnauthorizedException; } if (payload.role_id == 1 || skipEndpoint.includes(getPAth)) { const user = await this.userRepository.findOne({ where: { id: payload.user_id, }, relations: ['role'], }); if (![null, undefined, ''].includes(user.refreshToken) && token == user.refreshToken) { return true } else { console.log(user.refreshToken, "user.refreshToken") console.log(getPAth, "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") throw new UnauthorizedException; } } else if (payload.role_id == 2 || skipEndpoint.includes(getPAth)) { if (![null, undefined, ''].includes("currentAccount.refreshToken") && token == "currentAccount.refreshToken") { console.log("its trueeeeeeee") return true } else { console.log("its not trueeeeeeee") throw new UnauthorizedException; } } else if (payload.role_id == 3 || skipEndpoint.includes(getPAth)) { if (![null, undefined, ''].includes("currentAccount.refreshToken") && token == "currentAccount.refreshToken") { console.log("its trueeeeeeee") return true } else { console.log("its not trueeeeeeee") throw new UnauthorizedException; } } else { const user = await this.userRepository.findOne({ where: { id: payload.user_id, }, relations: ['role'], }); if (![null, undefined, ''].includes(user.refreshToken) && token == user.refreshToken) { const checkPermission = await this.permissionRepository.find({ where: { role: { id: payload.role_id } }, relations: ['aclMenu'], }) const arr = checkPermission.map((element) => element.aclMenu.url); const getPAth = roles[0] if (arr.includes(getPAth)) { return true } else if (viewForUpdate.includes(getPAth)) { if (arr.some(item => checkForUpdate.includes(item))) { return true; } return false } else if (listPermission.includes(getPAth)) { return true; } } else { throw new UnauthorizedException; } } } } catch (error) { console.log("catch function is starttttttttttttttt") console.log(error, "********************************") if (error.name === 'TokenExpiredError') { // Handle JWT expiry error here console.log('JWT token has expired.'); throw new UnauthorizedException('JWT token has expired', 'JWT_EXPIRED'); } else { // Handle other JWT verification errors console.log('JWT verification error:', error); throw new UnauthorizedException; } } } }
/var/snap/.././lib/../www/talentgenesis_admin_backend/src/guards/auth.guard.ts