I got two classes; authenticationRoutes.ts and authenticationController.ts. In authenticationRoutes I'm calling 'authenticationController.test', the 'authenticationController.test' method calls 'authenticationController.generateAccessAuthToken' method. Whenever I do this I get the following Error: Unhandled rejection TypeError: Cannot read property 'generateAccessAuthToken' of undefined
authenticationRoutes.ts
import { authenticationController } from '../controllers/authenticationController';
//TEST ROUTE
this.router.get('/users', authenticationController.test);
authenticationController.ts
public test(req: Request, res: Response) {
dbSequelize().User.findAll({
where: {
id: '0'
},
attributes: ['id']
}).then((user: UserInstance[]) => {
this.generateAccessAuthToken('0').then((response: any) => {
console.log(response);
res.send(response);
});
})
}
generateAccessAuthToken(_id: any) {
return new Promise(async (resolve, reject) => {
await jwt.sign({ id: _id }, SECRET_KEY as string, function (err: Error, token: any) {
if (err) {
reject(err);
} else {
resolve(token);
}
})
})
}
I want to be able to do what I described without receiving an error.