|
|
@ -6,7 +6,7 @@ import { |
|
|
Injectable, |
|
|
Injectable, |
|
|
} from '@nestjs/common' |
|
|
} from '@nestjs/common' |
|
|
import { JwtService } from '@nestjs/jwt' |
|
|
import { JwtService } from '@nestjs/jwt' |
|
|
import { UsersService } from 'src/users/users.service' |
|
|
|
|
|
|
|
|
import { UsersService } from '../../users/users.service' |
|
|
import { AuthService } from '../auth.service' |
|
|
import { AuthService } from '../auth.service' |
|
|
import * as bcrypt from 'bcryptjs' |
|
|
import * as bcrypt from 'bcryptjs' |
|
|
|
|
|
|
|
|
@ -32,15 +32,13 @@ export class AuthGuard implements CanActivate { |
|
|
// check apiKey in query params
|
|
|
// check apiKey in query params
|
|
|
else if (request.query.apiKey) { |
|
|
else if (request.query.apiKey) { |
|
|
const apiKeyStr = request.query.apiKey |
|
|
const apiKeyStr = request.query.apiKey |
|
|
if (apiKeyStr) { |
|
|
|
|
|
var regex = new RegExp(`^${apiKeyStr.substr(0, 17)}`, 'g') |
|
|
|
|
|
const apiKey = await this.authService.findApiKey({ |
|
|
|
|
|
apiKey: { $regex: regex }, |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
const regex = new RegExp(`^${apiKeyStr.substr(0, 17)}`, 'g') |
|
|
|
|
|
const apiKey = await this.authService.findApiKey({ |
|
|
|
|
|
apiKey: { $regex: regex }, |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
if (apiKey && bcrypt.compareSync(apiKeyStr, apiKey.hashedApiKey)) { |
|
|
|
|
|
userId = apiKey.user |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (apiKey && bcrypt.compareSync(apiKeyStr, apiKey.hashedApiKey)) { |
|
|
|
|
|
userId = apiKey.user |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|