Skip to content
This repository has been archived by the owner on Dec 19, 2021. It is now read-only.

restyjs-graveyard/jwt

Repository files navigation

@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: "[email protected]",
    });

    return {
      token,
    };
  }

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

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

app.listen(8080);