Skip to content

Commit 8f236e8

Browse files
Add NestJS SDK (@thunderid/nestjs)
1 parent a50ef7a commit 8f236e8

23 files changed

Lines changed: 1160 additions & 0 deletions

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ JavaScript SDKs for ThunderID. Provides authentication and user management for b
1515
| [`@thunderid/vue`](packages/vue) | ![npm](https://img.shields.io/npm/v/@thunderid/vue) | Vue SDK |
1616
| [`@thunderid/nuxt`](packages/nuxt) | ![npm](https://img.shields.io/npm/v/@thunderid/nuxt) | Nuxt SDK |
1717
| [`@thunderid/express`](packages/express) | ![npm](https://img.shields.io/npm/v/@thunderid/express) | Express.js SDK |
18+
| [`@thunderid/nestjs`](packages/nestjs) | ![npm](https://img.shields.io/npm/v/@thunderid/nestjs) | NestJS SDK |
1819
| [`@thunderid/tanstack-router`](packages/tanstack-router) | ![npm](https://img.shields.io/npm/v/@thunderid/tanstack-router) | TanStack Router integration |
1920

2021
## License

‎packages/nestjs/.editorconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../.editorconfig

‎packages/nestjs/.gitignore‎

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# Snowpack dependency directory (https://snowpack.dev/)
45+
web_modules/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Optional stylelint cache
57+
.stylelintcache
58+
59+
# Optional REPL history
60+
.node_repl_history
61+
62+
# Output of 'npm pack'
63+
*.tgz
64+
65+
# Yarn Integrity file
66+
.yarn-integrity
67+
68+
# dotenv environment variable files
69+
.env
70+
.env.*
71+
!.env.example
72+
73+
# parcel-bundler cache (https://parceljs.org/)
74+
.cache
75+
.parcel-cache
76+
77+
# Next.js build output
78+
.next
79+
out
80+
81+
# Nuxt.js build / generate output
82+
.nuxt
83+
dist
84+
.output
85+
86+
# Gatsby files
87+
.cache/
88+
# Comment in the public line in if your project uses Gatsby and not Next.js
89+
# https://nextjs.org/blog/next-9-1#public-directory-support
90+
# public
91+
92+
# vuepress build output
93+
.vuepress/dist
94+
95+
# vuepress v2.x temp and cache directory
96+
.temp
97+
.cache
98+
99+
# Sveltekit cache directory
100+
.svelte-kit/
101+
102+
# vitepress build output
103+
**/.vitepress/dist
104+
105+
# vitepress cache directory
106+
**/.vitepress/cache
107+
108+
# Docusaurus cache and generated files
109+
.docusaurus
110+
111+
# Serverless directories
112+
.serverless/
113+
114+
# FuseBox cache
115+
.fusebox/
116+
117+
# DynamoDB Local files
118+
.dynamodb/
119+
120+
# Firebase cache directory
121+
.firebase/
122+
123+
# TernJS port file
124+
.tern-port
125+
126+
# Stores VSCode versions used for testing VSCode extensions
127+
.vscode-test
128+
129+
# yarn v3
130+
.pnp.*
131+
.yarn/*
132+
!.yarn/patches
133+
!.yarn/plugins
134+
!.yarn/releases
135+
!.yarn/sdks
136+
!.yarn/versions
137+
138+
# Vite files
139+
vite.config.js.timestamp-*
140+
vite.config.ts.timestamp-*
141+
.vite/

‎packages/nestjs/.prettierignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/dist
2+
/build
3+
/node_modules
4+
/coverage

‎packages/nestjs/README.md‎

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# @thunderid/nestjs
2+
3+
NestJS SDK for [ThunderID](https://github.com/thunder-id/thunderid). Built on top of [`@thunderid/express`](../express)
4+
— works with NestJS applications running on the default Express platform.
5+
6+
## Installation
7+
8+
```bash
9+
npm install @thunderid/nestjs cookie-parser
10+
```
11+
12+
## Setup
13+
14+
Register `cookie-parser` and the ThunderID module:
15+
16+
```ts
17+
// main.ts
18+
import cookieParser from 'cookie-parser';
19+
20+
const app = await NestFactory.create(AppModule);
21+
app.use(cookieParser());
22+
```
23+
24+
```ts
25+
// app.module.ts
26+
import {ThunderIDModule} from '@thunderid/nestjs';
27+
28+
@Module({
29+
imports: [
30+
ThunderIDModule.forRoot({
31+
clientId: process.env.THUNDERID_CLIENT_ID,
32+
baseUrl: process.env.THUNDERID_BASE_URL,
33+
}),
34+
],
35+
})
36+
export class AppModule {}
37+
```
38+
39+
The module is global — `ThunderIDService` and `ThunderIDGuard` are injectable everywhere.
40+
41+
## Sign-in / sign-out routes
42+
43+
```ts
44+
import {Request, Response} from 'express';
45+
import {ThunderIDService} from '@thunderid/nestjs';
46+
47+
@Controller()
48+
export class AuthController {
49+
constructor(private readonly thunderID: ThunderIDService) {}
50+
51+
@Get('login')
52+
async login(@Req() req: Request, @Res() res: Response) {
53+
const tokens = await this.thunderID.signIn(req, res);
54+
if (tokens.accessToken || tokens.idToken) {
55+
res.redirect('/');
56+
}
57+
}
58+
59+
@Get('logout')
60+
async logout(@Req() req: Request, @Res() res: Response) {
61+
if (this.thunderID.isSignOutSuccess(req)) {
62+
res.redirect('/');
63+
return;
64+
}
65+
await this.thunderID.signOut(req, res);
66+
}
67+
}
68+
```
69+
70+
## Protecting routes
71+
72+
```ts
73+
import {CurrentUser, ThunderIDGuard, User} from '@thunderid/nestjs';
74+
75+
@Controller()
76+
export class ProfileController {
77+
@UseGuards(ThunderIDGuard)
78+
@Get('profile')
79+
profile(@CurrentUser() user: User) {
80+
return user;
81+
}
82+
}
83+
```
84+
85+
`ThunderIDGuard` returns `401 Unauthorized` for requests without a valid session. `@CurrentUser()` resolves the
86+
authenticated user attached by the guard.
87+
88+
## API
89+
90+
| Export | Description |
91+
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
92+
| `ThunderIDModule.forRoot(config)` | Global module; accepts `ThunderIDNestConfig` (same shape as the Node SDK config) |
93+
| `ThunderIDService` | `signIn(req, res)`, `signOut(req, res)`, `isSignOutSuccess(req)`, `isSignedIn(req)`, `getUser(req)`, `getClient()` |
94+
| `ThunderIDGuard` | Route guard that blocks unauthenticated requests |
95+
| `@CurrentUser()` | Param decorator resolving the authenticated `User` (requires `ThunderIDGuard`) |
96+
97+
Everything from `@thunderid/express` (and transitively `@thunderid/node` / `@thunderid/javascript`) is re-exported.
98+
99+
## License
100+
101+
Apache-2.0

‎packages/nestjs/eslint.config.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com).
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
import thunderIdPlugin from '@thunderid/eslint-plugin';
20+
21+
export default [
22+
{
23+
ignores: ['dist/**', 'build/**', 'node_modules/**', 'coverage/**'],
24+
},
25+
...thunderIdPlugin.configs.typescript,
26+
...thunderIdPlugin.configs.vitest,
27+
];

‎packages/nestjs/package.json‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
"name": "@thunderid/nestjs",
3+
"version": "0.1.0",
4+
"description": "NestJS SDK for ThunderID",
5+
"keywords": [
6+
"thunderid",
7+
"nestjs",
8+
"server"
9+
],
10+
"homepage": "https://github.com/thunder-id/javascript-sdks/tree/main/packages/nestjs#readme",
11+
"bugs": {
12+
"url": "https://github.com/thunder-id/thunderid/issues"
13+
},
14+
"author": "WSO2",
15+
"license": "Apache-2.0",
16+
"type": "module",
17+
"main": "dist/index.js",
18+
"module": "dist/index.js",
19+
"commonjs": "dist/cjs/index.cjs",
20+
"exports": {
21+
".": {
22+
"types": "./dist/index.d.ts",
23+
"import": "./dist/index.js",
24+
"require": "./dist/cjs/index.cjs"
25+
}
26+
},
27+
"files": [
28+
"dist",
29+
"README.md",
30+
"LICENSE"
31+
],
32+
"types": "dist/index.d.ts",
33+
"repository": {
34+
"type": "git",
35+
"url": "https://github.com/thunder-id/javascript-sdks",
36+
"directory": "packages/nestjs"
37+
},
38+
"scripts": {
39+
"build": "pnpm clean:dist && rolldown -c rolldown.config.js && tsc -p tsconfig.lib.json --emitDeclarationOnly --outDir dist",
40+
"clean": "pnpm clean:node_modules && pnpm clean:dist",
41+
"clean:dist": "rimraf dist",
42+
"clean:node_modules": "rimraf node_modules",
43+
"format:check": "prettier --check --cache .",
44+
"format:fix": "prettier --write --cache .",
45+
"lint": "eslint . --ext .js,.jsx,.ts,.tsx,.cjs,.mjs",
46+
"lint:fix": "eslint . --fix --ext .js,.jsx,.ts,.tsx,.cjs,.mjs",
47+
"test": "vitest run --passWithNoTests",
48+
"typecheck": "tsc -p tsconfig.lib.json"
49+
},
50+
"devDependencies": {
51+
"@nestjs/common": "^11.0.0",
52+
"@thunderid/eslint-plugin": "catalog:",
53+
"@thunderid/prettier-config": "catalog:",
54+
"@types/cookie-parser": "^1.4.8",
55+
"@types/express": "^5.0.6",
56+
"@types/node": "22.15.3",
57+
"eslint": "catalog:",
58+
"prettier": "catalog:",
59+
"reflect-metadata": "^0.2.2",
60+
"rimraf": "catalog:",
61+
"rolldown": "catalog:",
62+
"rxjs": "^7.8.1",
63+
"typescript": "catalog:",
64+
"vitest": "catalog:"
65+
},
66+
"dependencies": {
67+
"@thunderid/express": "workspace:^"
68+
},
69+
"peerDependencies": {
70+
"@nestjs/common": ">=10.0.0"
71+
},
72+
"publishConfig": {
73+
"access": "public"
74+
}
75+
}

‎packages/nestjs/prettier.config.js‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com).
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
import config from '@thunderid/prettier-config';
20+
21+
export default config;

0 commit comments

Comments
 (0)