Node JS self._callback.apply is not a function error










1














 import axios from 'axios';
import * as jwt from 'jsonwebtoken';
import Action from 'routing-controllers';
import Connection from 'typeorm';

import env from '../env';

export function authorizationChecker( connection: Connection): (action: Action, roles: any) => Promise<boolean> | boolean
let validationKey: any = axios.get(env.auth.jwksUri).then(response =>
validationKey = response.data.keys[0].value;
).catch();
return async function innerAuthorizationChecker(
action: Action,
roles: string
): Promise<boolean>
// here you can use request/response objects from action
// also if decorator defines roles it needs to access the actio
// you can use them to provide granular access check
// checker must return either boolean (true or false)
// either promise that resolves a boolean value
try
action.request.headers.authorization).replace('Bearer ', '');
await jwt.verify(token, validationKey);
return true;
catch (e)
return false;

;



This is my error:



error: [app] Application is crashed: TypeError: self._callback.apply is not a function
(node:512) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property '0' of undefined
(node:512) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js
process with a non-zero exit code.



I'm trying to get the validation key set from a specific URL from a service, but somehow (without calling the function) it says that the response data is undefined. On top of that, I'm having this error: self._callback.apply is not a function.



Has someone dealt with such a callback error before? I couldn't find anything on stackoverflow relating to my problem.










share|improve this question



















  • 2




    response.data.keys[0] has a "property 0", so the error implies that keys there is not actually defined. Also a lot of other problems here. return async function() does not do what you seem to think it does, and it's not really clear here what you are expecting. Needs more context as well as some basic debugging.
    – Neil Lunn
    Nov 12 at 8:52










  • I know that response.data.keys[0] is not defined. but how can it be defined if the value is being called from an api?
    – Slyckies
    Nov 12 at 12:30















1














 import axios from 'axios';
import * as jwt from 'jsonwebtoken';
import Action from 'routing-controllers';
import Connection from 'typeorm';

import env from '../env';

export function authorizationChecker( connection: Connection): (action: Action, roles: any) => Promise<boolean> | boolean
let validationKey: any = axios.get(env.auth.jwksUri).then(response =>
validationKey = response.data.keys[0].value;
).catch();
return async function innerAuthorizationChecker(
action: Action,
roles: string
): Promise<boolean>
// here you can use request/response objects from action
// also if decorator defines roles it needs to access the actio
// you can use them to provide granular access check
// checker must return either boolean (true or false)
// either promise that resolves a boolean value
try
action.request.headers.authorization).replace('Bearer ', '');
await jwt.verify(token, validationKey);
return true;
catch (e)
return false;

;



This is my error:



error: [app] Application is crashed: TypeError: self._callback.apply is not a function
(node:512) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property '0' of undefined
(node:512) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js
process with a non-zero exit code.



I'm trying to get the validation key set from a specific URL from a service, but somehow (without calling the function) it says that the response data is undefined. On top of that, I'm having this error: self._callback.apply is not a function.



Has someone dealt with such a callback error before? I couldn't find anything on stackoverflow relating to my problem.










share|improve this question



















  • 2




    response.data.keys[0] has a "property 0", so the error implies that keys there is not actually defined. Also a lot of other problems here. return async function() does not do what you seem to think it does, and it's not really clear here what you are expecting. Needs more context as well as some basic debugging.
    – Neil Lunn
    Nov 12 at 8:52










  • I know that response.data.keys[0] is not defined. but how can it be defined if the value is being called from an api?
    – Slyckies
    Nov 12 at 12:30













1












1








1







 import axios from 'axios';
import * as jwt from 'jsonwebtoken';
import Action from 'routing-controllers';
import Connection from 'typeorm';

import env from '../env';

export function authorizationChecker( connection: Connection): (action: Action, roles: any) => Promise<boolean> | boolean
let validationKey: any = axios.get(env.auth.jwksUri).then(response =>
validationKey = response.data.keys[0].value;
).catch();
return async function innerAuthorizationChecker(
action: Action,
roles: string
): Promise<boolean>
// here you can use request/response objects from action
// also if decorator defines roles it needs to access the actio
// you can use them to provide granular access check
// checker must return either boolean (true or false)
// either promise that resolves a boolean value
try
action.request.headers.authorization).replace('Bearer ', '');
await jwt.verify(token, validationKey);
return true;
catch (e)
return false;

;



This is my error:



error: [app] Application is crashed: TypeError: self._callback.apply is not a function
(node:512) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property '0' of undefined
(node:512) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js
process with a non-zero exit code.



I'm trying to get the validation key set from a specific URL from a service, but somehow (without calling the function) it says that the response data is undefined. On top of that, I'm having this error: self._callback.apply is not a function.



Has someone dealt with such a callback error before? I couldn't find anything on stackoverflow relating to my problem.










share|improve this question















 import axios from 'axios';
import * as jwt from 'jsonwebtoken';
import Action from 'routing-controllers';
import Connection from 'typeorm';

import env from '../env';

export function authorizationChecker( connection: Connection): (action: Action, roles: any) => Promise<boolean> | boolean
let validationKey: any = axios.get(env.auth.jwksUri).then(response =>
validationKey = response.data.keys[0].value;
).catch();
return async function innerAuthorizationChecker(
action: Action,
roles: string
): Promise<boolean>
// here you can use request/response objects from action
// also if decorator defines roles it needs to access the actio
// you can use them to provide granular access check
// checker must return either boolean (true or false)
// either promise that resolves a boolean value
try
action.request.headers.authorization).replace('Bearer ', '');
await jwt.verify(token, validationKey);
return true;
catch (e)
return false;

;



This is my error:



error: [app] Application is crashed: TypeError: self._callback.apply is not a function
(node:512) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property '0' of undefined
(node:512) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js
process with a non-zero exit code.



I'm trying to get the validation key set from a specific URL from a service, but somehow (without calling the function) it says that the response data is undefined. On top of that, I'm having this error: self._callback.apply is not a function.



Has someone dealt with such a callback error before? I couldn't find anything on stackoverflow relating to my problem.







javascript node.js typescript callback






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 9:33









Hannah May

1226




1226










asked Nov 12 at 8:45









Slyckies

62




62







  • 2




    response.data.keys[0] has a "property 0", so the error implies that keys there is not actually defined. Also a lot of other problems here. return async function() does not do what you seem to think it does, and it's not really clear here what you are expecting. Needs more context as well as some basic debugging.
    – Neil Lunn
    Nov 12 at 8:52










  • I know that response.data.keys[0] is not defined. but how can it be defined if the value is being called from an api?
    – Slyckies
    Nov 12 at 12:30












  • 2




    response.data.keys[0] has a "property 0", so the error implies that keys there is not actually defined. Also a lot of other problems here. return async function() does not do what you seem to think it does, and it's not really clear here what you are expecting. Needs more context as well as some basic debugging.
    – Neil Lunn
    Nov 12 at 8:52










  • I know that response.data.keys[0] is not defined. but how can it be defined if the value is being called from an api?
    – Slyckies
    Nov 12 at 12:30







2




2




response.data.keys[0] has a "property 0", so the error implies that keys there is not actually defined. Also a lot of other problems here. return async function() does not do what you seem to think it does, and it's not really clear here what you are expecting. Needs more context as well as some basic debugging.
– Neil Lunn
Nov 12 at 8:52




response.data.keys[0] has a "property 0", so the error implies that keys there is not actually defined. Also a lot of other problems here. return async function() does not do what you seem to think it does, and it's not really clear here what you are expecting. Needs more context as well as some basic debugging.
– Neil Lunn
Nov 12 at 8:52












I know that response.data.keys[0] is not defined. but how can it be defined if the value is being called from an api?
– Slyckies
Nov 12 at 12:30




I know that response.data.keys[0] is not defined. but how can it be defined if the value is being called from an api?
– Slyckies
Nov 12 at 12:30

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53258512%2fnode-js-self-callback-apply-is-not-a-function-error%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53258512%2fnode-js-self-callback-apply-is-not-a-function-error%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3