Axios Patch On FeathersJs No auth token
I have a problem with Patch in FeathersJS.
I want to update the data with axios.patch
but the message that appears is always No auth token
{"name":"NotAuthenticated","message":"No auth token","code":401,"className":"not-authenticated","data":{},"errors":{}}
This my axios :
Aktifasi() {
axios.patch(process.env.ROOT_API+'/ek_user?id_user=2',
qs.stringify({
headers: {
'Authorization': 'Bearer ' + localStorage.getItem('token'),
'Content-Type': 'application/json',
},
active_user: 1
}))
.then(request => this.AktifasiSuccesSend(request))
.catch((error) => this.AktifasiFailedSend(error))
},
AktifasiSuccesSend (request) {
console.log('Yay');
},
AktifasiFailedSend (error) {
console.log('Oh Fail');
}
And this Hook on FeathersJS :
before: {
all: ,
find: [ authenticate('jwt') ],
get: [ authenticate('jwt') ],
create: [ hashPassword() ],
update: [ hashPassword(), authenticate('jwt') ],
patch: [ hashPassword(), authenticate('jwt') ],
remove: [ authenticate('jwt') ]
},
feathersjs
add a comment |
I have a problem with Patch in FeathersJS.
I want to update the data with axios.patch
but the message that appears is always No auth token
{"name":"NotAuthenticated","message":"No auth token","code":401,"className":"not-authenticated","data":{},"errors":{}}
This my axios :
Aktifasi() {
axios.patch(process.env.ROOT_API+'/ek_user?id_user=2',
qs.stringify({
headers: {
'Authorization': 'Bearer ' + localStorage.getItem('token'),
'Content-Type': 'application/json',
},
active_user: 1
}))
.then(request => this.AktifasiSuccesSend(request))
.catch((error) => this.AktifasiFailedSend(error))
},
AktifasiSuccesSend (request) {
console.log('Yay');
},
AktifasiFailedSend (error) {
console.log('Oh Fail');
}
And this Hook on FeathersJS :
before: {
all: ,
find: [ authenticate('jwt') ],
get: [ authenticate('jwt') ],
create: [ hashPassword() ],
update: [ hashPassword(), authenticate('jwt') ],
patch: [ hashPassword(), authenticate('jwt') ],
remove: [ authenticate('jwt') ]
},
feathersjs
add a comment |
I have a problem with Patch in FeathersJS.
I want to update the data with axios.patch
but the message that appears is always No auth token
{"name":"NotAuthenticated","message":"No auth token","code":401,"className":"not-authenticated","data":{},"errors":{}}
This my axios :
Aktifasi() {
axios.patch(process.env.ROOT_API+'/ek_user?id_user=2',
qs.stringify({
headers: {
'Authorization': 'Bearer ' + localStorage.getItem('token'),
'Content-Type': 'application/json',
},
active_user: 1
}))
.then(request => this.AktifasiSuccesSend(request))
.catch((error) => this.AktifasiFailedSend(error))
},
AktifasiSuccesSend (request) {
console.log('Yay');
},
AktifasiFailedSend (error) {
console.log('Oh Fail');
}
And this Hook on FeathersJS :
before: {
all: ,
find: [ authenticate('jwt') ],
get: [ authenticate('jwt') ],
create: [ hashPassword() ],
update: [ hashPassword(), authenticate('jwt') ],
patch: [ hashPassword(), authenticate('jwt') ],
remove: [ authenticate('jwt') ]
},
feathersjs
I have a problem with Patch in FeathersJS.
I want to update the data with axios.patch
but the message that appears is always No auth token
{"name":"NotAuthenticated","message":"No auth token","code":401,"className":"not-authenticated","data":{},"errors":{}}
This my axios :
Aktifasi() {
axios.patch(process.env.ROOT_API+'/ek_user?id_user=2',
qs.stringify({
headers: {
'Authorization': 'Bearer ' + localStorage.getItem('token'),
'Content-Type': 'application/json',
},
active_user: 1
}))
.then(request => this.AktifasiSuccesSend(request))
.catch((error) => this.AktifasiFailedSend(error))
},
AktifasiSuccesSend (request) {
console.log('Yay');
},
AktifasiFailedSend (error) {
console.log('Oh Fail');
}
And this Hook on FeathersJS :
before: {
all: ,
find: [ authenticate('jwt') ],
get: [ authenticate('jwt') ],
create: [ hashPassword() ],
update: [ hashPassword(), authenticate('jwt') ],
patch: [ hashPassword(), authenticate('jwt') ],
remove: [ authenticate('jwt') ]
},
feathersjs
feathersjs
asked Nov 11 '18 at 16:57
prapto herlambang
75
75
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
As the Axios configuration documentation shows, headers
are passed as a separate option not as a stringified query string (which shouldn't be necessary at all):
const data = {
active_user: 1
};
const config = {
headers: {
'Authorization': 'Bearer ' + localStorage.getItem('token'),
'Content-Type': 'application/json',
}
};
axios.patch(process.env.ROOT_API + '/ek_user?id_user=2', data, config);
thank you master @Daff
– prapto herlambang
Nov 15 '18 at 17:31
add a comment |
I recommend becoming very good at using a proper Node debugger. Visual Studio Code has a great debugger. I even wrote an article about it on the Feathers blog: https://blog.feathersjs.com/debugging-feathers-with-visual-studio-code-406e6adf2882
I will give you some pointers to get you on your way, but you will be required to answer your own question by using a debugger.
The "No auth token" message that you are getting is coming from the authenticate('jwt')
hook. Here are some typical steps you'd use to solve your own problem:
- If you open that hook in your node_modules folder and put break points in it before the message, you'll be able to see where it's looking for a jwt token.
- If you create a hook before all other hooks in the
patch
hooks, you'll be able to put a break point in it and inspect the hook context object to see if the request contains the jwt, or not (in the same location that theauthenticate
hook expects it. - If the jwt token is not in the place where the
authenticate
hook expects to find it, you may be missing a middleware function registration in yourauthentication.js
setup file. You would check the feathers docs to make sure you've properly registered the authentication plugins.
thank you master @Marshall
– prapto herlambang
Nov 15 '18 at 17:31
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251044%2faxios-patch-on-feathersjs-no-auth-token%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
As the Axios configuration documentation shows, headers
are passed as a separate option not as a stringified query string (which shouldn't be necessary at all):
const data = {
active_user: 1
};
const config = {
headers: {
'Authorization': 'Bearer ' + localStorage.getItem('token'),
'Content-Type': 'application/json',
}
};
axios.patch(process.env.ROOT_API + '/ek_user?id_user=2', data, config);
thank you master @Daff
– prapto herlambang
Nov 15 '18 at 17:31
add a comment |
As the Axios configuration documentation shows, headers
are passed as a separate option not as a stringified query string (which shouldn't be necessary at all):
const data = {
active_user: 1
};
const config = {
headers: {
'Authorization': 'Bearer ' + localStorage.getItem('token'),
'Content-Type': 'application/json',
}
};
axios.patch(process.env.ROOT_API + '/ek_user?id_user=2', data, config);
thank you master @Daff
– prapto herlambang
Nov 15 '18 at 17:31
add a comment |
As the Axios configuration documentation shows, headers
are passed as a separate option not as a stringified query string (which shouldn't be necessary at all):
const data = {
active_user: 1
};
const config = {
headers: {
'Authorization': 'Bearer ' + localStorage.getItem('token'),
'Content-Type': 'application/json',
}
};
axios.patch(process.env.ROOT_API + '/ek_user?id_user=2', data, config);
As the Axios configuration documentation shows, headers
are passed as a separate option not as a stringified query string (which shouldn't be necessary at all):
const data = {
active_user: 1
};
const config = {
headers: {
'Authorization': 'Bearer ' + localStorage.getItem('token'),
'Content-Type': 'application/json',
}
};
axios.patch(process.env.ROOT_API + '/ek_user?id_user=2', data, config);
answered Nov 12 '18 at 5:08
Daff
36.1k783102
36.1k783102
thank you master @Daff
– prapto herlambang
Nov 15 '18 at 17:31
add a comment |
thank you master @Daff
– prapto herlambang
Nov 15 '18 at 17:31
thank you master @Daff
– prapto herlambang
Nov 15 '18 at 17:31
thank you master @Daff
– prapto herlambang
Nov 15 '18 at 17:31
add a comment |
I recommend becoming very good at using a proper Node debugger. Visual Studio Code has a great debugger. I even wrote an article about it on the Feathers blog: https://blog.feathersjs.com/debugging-feathers-with-visual-studio-code-406e6adf2882
I will give you some pointers to get you on your way, but you will be required to answer your own question by using a debugger.
The "No auth token" message that you are getting is coming from the authenticate('jwt')
hook. Here are some typical steps you'd use to solve your own problem:
- If you open that hook in your node_modules folder and put break points in it before the message, you'll be able to see where it's looking for a jwt token.
- If you create a hook before all other hooks in the
patch
hooks, you'll be able to put a break point in it and inspect the hook context object to see if the request contains the jwt, or not (in the same location that theauthenticate
hook expects it. - If the jwt token is not in the place where the
authenticate
hook expects to find it, you may be missing a middleware function registration in yourauthentication.js
setup file. You would check the feathers docs to make sure you've properly registered the authentication plugins.
thank you master @Marshall
– prapto herlambang
Nov 15 '18 at 17:31
add a comment |
I recommend becoming very good at using a proper Node debugger. Visual Studio Code has a great debugger. I even wrote an article about it on the Feathers blog: https://blog.feathersjs.com/debugging-feathers-with-visual-studio-code-406e6adf2882
I will give you some pointers to get you on your way, but you will be required to answer your own question by using a debugger.
The "No auth token" message that you are getting is coming from the authenticate('jwt')
hook. Here are some typical steps you'd use to solve your own problem:
- If you open that hook in your node_modules folder and put break points in it before the message, you'll be able to see where it's looking for a jwt token.
- If you create a hook before all other hooks in the
patch
hooks, you'll be able to put a break point in it and inspect the hook context object to see if the request contains the jwt, or not (in the same location that theauthenticate
hook expects it. - If the jwt token is not in the place where the
authenticate
hook expects to find it, you may be missing a middleware function registration in yourauthentication.js
setup file. You would check the feathers docs to make sure you've properly registered the authentication plugins.
thank you master @Marshall
– prapto herlambang
Nov 15 '18 at 17:31
add a comment |
I recommend becoming very good at using a proper Node debugger. Visual Studio Code has a great debugger. I even wrote an article about it on the Feathers blog: https://blog.feathersjs.com/debugging-feathers-with-visual-studio-code-406e6adf2882
I will give you some pointers to get you on your way, but you will be required to answer your own question by using a debugger.
The "No auth token" message that you are getting is coming from the authenticate('jwt')
hook. Here are some typical steps you'd use to solve your own problem:
- If you open that hook in your node_modules folder and put break points in it before the message, you'll be able to see where it's looking for a jwt token.
- If you create a hook before all other hooks in the
patch
hooks, you'll be able to put a break point in it and inspect the hook context object to see if the request contains the jwt, or not (in the same location that theauthenticate
hook expects it. - If the jwt token is not in the place where the
authenticate
hook expects to find it, you may be missing a middleware function registration in yourauthentication.js
setup file. You would check the feathers docs to make sure you've properly registered the authentication plugins.
I recommend becoming very good at using a proper Node debugger. Visual Studio Code has a great debugger. I even wrote an article about it on the Feathers blog: https://blog.feathersjs.com/debugging-feathers-with-visual-studio-code-406e6adf2882
I will give you some pointers to get you on your way, but you will be required to answer your own question by using a debugger.
The "No auth token" message that you are getting is coming from the authenticate('jwt')
hook. Here are some typical steps you'd use to solve your own problem:
- If you open that hook in your node_modules folder and put break points in it before the message, you'll be able to see where it's looking for a jwt token.
- If you create a hook before all other hooks in the
patch
hooks, you'll be able to put a break point in it and inspect the hook context object to see if the request contains the jwt, or not (in the same location that theauthenticate
hook expects it. - If the jwt token is not in the place where the
authenticate
hook expects to find it, you may be missing a middleware function registration in yourauthentication.js
setup file. You would check the feathers docs to make sure you've properly registered the authentication plugins.
answered Nov 12 '18 at 4:45
Marshall Thompson
5702617
5702617
thank you master @Marshall
– prapto herlambang
Nov 15 '18 at 17:31
add a comment |
thank you master @Marshall
– prapto herlambang
Nov 15 '18 at 17:31
thank you master @Marshall
– prapto herlambang
Nov 15 '18 at 17:31
thank you master @Marshall
– prapto herlambang
Nov 15 '18 at 17:31
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251044%2faxios-patch-on-feathersjs-no-auth-token%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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