npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@quickts/nestjs-auth

v2.0.0

Published

A quickts project

Downloads

8

Readme

nestjs-auth

Installation

$ npm install @quickts/nestjs-auth

Usage

// file: app.module.ts
import { Module } from "@nestjs/common";
import { AuthModule } from "@quickts/nestjs-auth";

const pubKey = `
-----BEGIN PUBLIC KEY-----
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKmndpB7Teiziw283cLtpTyW1Br9qegd
C7zDLJCkpEP0MMZTsciXQLShQaz0IsppmU2YSztLjjQe/5KYJtB58p8CAwEAAQ==
-----END PUBLIC KEY-----
`;

const priKey = `
-----BEGIN PRIVATE KEY-----
MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqad2kHtN6LOLDbzd
wu2lPJbUGv2p6B0LvMMskKSkQ/QwxlOxyJdAtKFBrPQiymmZTZhLO0uONB7/kpgm
0HnynwIDAQABAkBDD0fFaofsMHQJlRsPPwJuhawHkzcC4eBO19MYxYuMtCeBJvNj
UsRLlYw/RCY3R48W5SYkbvZAsCE+Nj821P/JAiEA07gfKdvjBCPM29VDbZeyR3q4
8mx9BX5Cxwy2A6bMgNMCIQDNIxeAXKsmD3PhIq7OPtL3b6HmDJwCVbjIn2yVaS3H
hQIhAIFIVmdGKVr2zXqTwKfkUO4LB3KpQrKfBgHsRhz2trwXAiAWjWYXCZkTTR2b
QbngGM4Ov+oXpYk9RHlVLRm971tGFQIgQRrltq6er2Kh2EXseewR4k9ixc5gM2PS
mA/bjYL6AJ8=
-----END PRIVATE KEY-----
`;

@Module({
    imports: [
        AuthModule.forRoot("quickts"), // 指定secret, 其他参数默认
        AuthModule.forRoot({
            secret: "quickts",
            signOptions: {
                noTimestamp: true
            }
        }), // 指定secret, 其他参数自定义
        AuthModule.forRoot({
            publicKey: pubKey,
            privateKey: priKey,
            signOptions: {
                algorithm: "RS256",
                noTimestamp: true
            }
        }) // 使用非对称加密
    ],
    controllers: []
})
export class ApplicationModule {}

// file: other.ts
import { Controller, Post, Get, Body } from "@nestjs/common";
import { AuthService } from "@quickts/nestjs-auth";
import { User, AuthCheck } from "@quickts/nestjs-auth";

@Controller()
class OtherController {
    constructor(private readonly authService: AuthService) {}

    @Post("create")
    create(@Body() data: { uid: number; name: string }) {
        const accessToken = this.authService.createToken(data, { expiresIn: 3600 }); // 创建token
        return accessToken;
    }

    @AuthCheck() // 使用装饰器验证token
    @Get("check")
    async check(
        @User("uid") uid: number //使用装饰器提取用户信息
    ) {
        return uid;
    }
}

http 请求时添加请求头 Authorization: Bearer ${token}