Skip to content

Instantly share code, notes, and snippets.

@dcortesnet
Last active February 14, 2023 12:21
Show Gist options
  • Select an option

  • Save dcortesnet/d31564929f3bd4562da333a67a277789 to your computer and use it in GitHub Desktop.

Select an option

Save dcortesnet/d31564929f3bd4562da333a67a277789 to your computer and use it in GitHub Desktop.
Nestjs example jwt provider
import { Injectable } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import jwt from "jsonwebtoken";
@Injectable()
export class JwtProvider {
constructor(private configService: ConfigService) {}
sign(payload: string) {
return jwt.sign(payload, this.configService.get<string>("JWT_SECRET"));
}
verify(token: string) {
return jwt.verify(token, this.configService.get<string>("JWT_SECRET"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment