okoala / koa-jwt2 Goto Github PK
View Code? Open in Web Editor NEWkoa middleware that validates a JsonWebToken (JWT) and sync with express/jwt
License: MIT License
koa middleware that validates a JsonWebToken (JWT) and sync with express/jwt
License: MIT License
When I am not passing token or passing invalid token while accessing protected url, it is giving me 401 error with "Unauthorised" message as plain text. I want that it should show error message as json.
app.use(async (ctx, next) => {
try {
await next();
} catch (err) {
logerr(err);
ctx.status = err.status || err.code;
ctx.body = {
status: false,
message: err.message,
};
}
});
It is not getting catched in the above function, but it is getting captured in below function.
app.on('error', (err, ctx) => {
logerr('onerr ', err);
if (err.name === "UnauthorizedError") {
ctx.status = 401;
ctx.body = "invalid token...";
}
});
But it is not showing me "Invalid token" message but it is throwing "Unauthorised" error as plain text.
Line 53 in 5b0dc88
1.Does koa-jwt2 have an expiry time and can I set this time?
2.How can I send token to client through my login api, this token used to verify in koa-jwt2's getToken function?
I have read your document several times, I didn't find the answer to the above question,could you please explain some for me,? thanks!
How can I make it possible to set a common and total 401 status in my koa2 app, while I'm using koa-router? Could you please give me some advice?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.