@restyjs/jwt
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

@restyjs/jwt

JWT middleware for resty.js.

import resty, { Controller, Get, Inject, Context } from "@restyjs/core";
import { JWTConfiguration, JWTProvider, ValidateJWT } from "@restyjs/jwt";


@Controller("/")
class HelloController {
  @Inject() jwtProvider!: JWTProvider;

  @Get("/generate")
  async generate() {
    const token = await this.jwtProvider.generate({
      id: 1,
      email: "foo@bar.com",
    });

    return {
      token,
    };
  }

  @Get("/validate", [ValidateJWT])
  validate(ctx: Context) {
    return {
      token: ctx.req.token,
    };
  }
}

const app = resty({
  controllers: [HelloController],
  providers: [JWTConfiguration("secret")],
});

app.listen(8080);

Dependents (0)

Package Sidebar

Install

npm i @restyjs/jwt

Homepage

restyjs.com

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

7.36 kB

Total Files

6

Last publish

Collaborators

  • satishbabariya