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

3.16.0 • Public • Published

开始

安装 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

Readme

Keywords

Package Sidebar

Install

npm i @midwayjs/jwt

Weekly Downloads

189

Version

3.16.0

License

MIT

Unpacked Size

16.1 kB

Total Files

12

Last publish

Collaborators

  • mariodu
  • czy88840616
  • legendecas
  • echosoar
  • lellansin
  • lxxyx
  • stone-jin