Giter Site home page Giter Site logo

koa-jwt2's People

Contributors

okoala avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

koa-jwt2's Issues

Thowing "Unauthorised" error as plain text

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.

two new questions

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!

a question about this package

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.