JSPM

  • Created
  • Published
  • Downloads 706
  • Score
    100M100P100Q96631F
  • License MIT

midway jwt component

Package Exports

  • @midwayjs/jwt
  • @midwayjs/jwt/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@midwayjs/jwt) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

开始

安装 npm i @midwayjs/jwt

可配合 @midwayjs/passport 使用

config.{env}.ts

config.jwt = {
  secret: 'dev123456',
  expiresIn: '10d', // https://github.com/vercel/ms
};
import { JWTService } from '@midwayjs/jwt';

@Provide()
class Demo {
  @Inject()
  jwt: JwtService;
}

API

请不要在 payload 存放任何敏感信息

  • public async sign(payload: JwtPayload, options?: SignOptions, secret?: Secret): Promise<string | void>

  • public signSync(payload: JwtPayload, options?: SignOptions, secret?: Secret): string | void

  • verifySync(token: string,options?: VerifyOptions & { complete: true },secret?: Secret): Jwt | string | JwtPayload

  • public async verify(token: string,options?: VerifyOptions & { complete: true },secret?: Secret | GetPublicKeyOrSecret): Promise<JwtType | undefined | JwtPayload>

  • decodeSync(token: string,options?: DecodeOptions & { complete: true } & { json: true }): Jwt | null | JwtPayload | string