Skip to content

Commit

Permalink
bug fix: displaying qrcode page
Browse files Browse the repository at this point in the history
  • Loading branch information
jrCleber committed Dec 21, 2023
1 parent b0ea822 commit 6e35bc8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,8 @@ export async function AppModule(context: Map<string, any>) {
session({
secret: configService.get<string>('SESSION_SECRET'),
resave: false,
saveUninitialized: true,
saveUninitialized: false,
name: 'codechat.api.sid',
cookie: { secure: true },
}),
);

Expand Down
4 changes: 4 additions & 0 deletions src/guards/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export class JwtGuard {
);
}

if (req.originalUrl.includes('/instance/qrcode')) {
return next();
}

const jwtOpts = this.configService.get<Auth>('AUTHENTICATION').JWT;
try {
const [bearer, token] = req.get('authorization')?.split(' ');
Expand Down
5 changes: 3 additions & 2 deletions src/guards/instance.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import { InstanceDto } from '../whatsapp/dto/instance.dto';
import { WAMonitoringService } from '../whatsapp/services/monitor.service';
import { RedisCache } from '../cache/redis';
import 'express-async-errors';
import { InstanceController } from '../whatsapp/controllers/instance.controller';

async function fetchInstanceFromCache(
instanceName: string,
Expand Down Expand Up @@ -98,7 +97,9 @@ export class InstanceGuard {

if (
req.originalUrl.includes('/instance/create') ||
req.originalUrl.includes('/instance/fetchInstances')
req.originalUrl.includes('/instance/fetchInstances') ||
req.originalUrl.includes('/instance/qrcode') ||
req.originalUrl.includes('/instance/connect')
) {
return next();
}
Expand Down
5 changes: 2 additions & 3 deletions src/whatsapp/controllers/views.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class ViewsController {
try {
const param = request.params as unknown as InstanceDto;
const instance = this.waMonit.waInstances[param.instanceName];
if (instance.connectionStatus.state === 'open') {
if (instance?.connectionStatus.state === 'open') {
throw new BadRequestException('The instance is already connected');
}

Expand All @@ -71,9 +71,8 @@ export class ViewsController {

return response.status(HttpStatus.OK).render('qrcode', {
...param,
type: 'jwt',
auth,
connectionState: instance.connectionStatus.state,
connectionState: instance?.connectionStatus.state || 'close',
});
} catch (error) {
console.log('ERROR: ', error);
Expand Down
4 changes: 1 addition & 3 deletions views/qrcode.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@
$('#gen-qrcode').click(() => {
const headers = '{{type}}' === 'apikey'
? { apikey: '{{auth.apikey}}' }
: { authorization: 'Bearer {{auth.jwt}}' };
const headers = { authorization: 'Bearer {{auth.token}}' }
$.ajax({
url: `/instance/connect/{{instanceName}}`,
Expand Down

0 comments on commit 6e35bc8

Please sign in to comment.