wexts 4.1.5 → 4.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -49
- package/bin/wexts.cjs +2 -2
- package/dist/chunk-27NEYQD2.mjs +222 -0
- package/dist/chunk-27NEYQD2.mjs.map +1 -0
- package/dist/chunk-2LJVUMXW.js +228 -0
- package/dist/chunk-2LJVUMXW.js.map +1 -0
- package/dist/chunk-5DBFN65W.mjs +183 -0
- package/dist/chunk-5DBFN65W.mjs.map +1 -0
- package/dist/chunk-75HBI2XG.js +504 -0
- package/dist/chunk-75HBI2XG.js.map +1 -0
- package/dist/chunk-AVMQJWYD.js +95 -0
- package/dist/chunk-AVMQJWYD.js.map +1 -0
- package/dist/chunk-C2AG7Q3C.mjs +65 -0
- package/dist/chunk-C2AG7Q3C.mjs.map +1 -0
- package/dist/chunk-DS5KVVWJ.mjs +95 -0
- package/dist/chunk-DS5KVVWJ.mjs.map +1 -0
- package/dist/chunk-FUPLZMSR.mjs +228 -0
- package/dist/chunk-FUPLZMSR.mjs.map +1 -0
- package/dist/chunk-HLT3IHJY.js +183 -0
- package/dist/chunk-HLT3IHJY.js.map +1 -0
- package/dist/chunk-IRRJJ7KL.js +273 -0
- package/dist/chunk-IRRJJ7KL.js.map +1 -0
- package/dist/chunk-L77ANWWT.mjs +22 -0
- package/dist/chunk-L77ANWWT.mjs.map +1 -0
- package/dist/chunk-P3Q4I5FD.js +222 -0
- package/dist/chunk-P3Q4I5FD.js.map +1 -0
- package/dist/chunk-VBIQGUDI.mjs +504 -0
- package/dist/chunk-VBIQGUDI.mjs.map +1 -0
- package/dist/chunk-VJY6PHYF.mjs +273 -0
- package/dist/chunk-VJY6PHYF.mjs.map +1 -0
- package/dist/chunk-WCKSKU3C.js +65 -0
- package/dist/chunk-WCKSKU3C.js.map +1 -0
- package/dist/chunk-XE4OXN2W.js +12 -0
- package/dist/chunk-XE4OXN2W.js.map +1 -0
- package/dist/cli/index.d.mts +23 -0
- package/dist/cli/index.d.ts +23 -0
- package/dist/cli/index.js +634 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/index.mjs +636 -0
- package/dist/cli/index.mjs.map +1 -0
- package/dist/client/index.d.mts +43 -0
- package/dist/client/index.d.ts +43 -0
- package/dist/client/index.js +187 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/index.mjs +166 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/codegen/index.d.mts +2 -0
- package/dist/codegen/index.d.ts +2 -0
- package/dist/codegen/index.js +16 -0
- package/dist/codegen/index.js.map +1 -0
- package/dist/codegen/index.mjs +16 -0
- package/dist/codegen/index.mjs.map +1 -0
- package/dist/decorators-BiQtOHuF.d.ts +60 -0
- package/dist/decorators-vBopODtr.d.mts +60 -0
- package/dist/dev-server/index.d.mts +1 -0
- package/dist/dev-server/index.d.ts +1 -0
- package/dist/dev-server/index.js +13 -0
- package/dist/dev-server/index.js.map +1 -0
- package/dist/dev-server/index.mjs +13 -0
- package/dist/dev-server/index.mjs.map +1 -0
- package/dist/errors-D545UvXf.d.mts +37 -0
- package/dist/errors-D545UvXf.d.ts +37 -0
- package/dist/index-7RvU-jGE.d.mts +66 -0
- package/dist/index-7RvU-jGE.d.ts +66 -0
- package/dist/index-BsafLP-a.d.mts +70 -0
- package/dist/index-BsafLP-a.d.ts +70 -0
- package/dist/index-CJKs4wtN.d.ts +92 -0
- package/dist/index-CUR6CnLk.d.ts +27 -0
- package/dist/index-h66Vq9dK.d.mts +92 -0
- package/dist/index-tqmYsTUn.d.mts +27 -0
- package/dist/index.d.mts +289 -0
- package/dist/index.d.ts +289 -0
- package/dist/index.js +544 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +544 -0
- package/dist/index.mjs.map +1 -0
- package/dist/nest/index.d.mts +2 -0
- package/dist/nest/index.d.ts +2 -0
- package/dist/nest/index.js +36 -0
- package/dist/nest/index.js.map +1 -0
- package/dist/nest/index.mjs +36 -0
- package/dist/nest/index.mjs.map +1 -0
- package/dist/next/index.d.mts +66 -0
- package/dist/next/index.d.ts +66 -0
- package/dist/next/index.js +282 -0
- package/dist/next/index.js.map +1 -0
- package/dist/next/index.mjs +251 -0
- package/dist/next/index.mjs.map +1 -0
- package/dist/rpc/index.d.mts +32 -0
- package/dist/rpc/index.d.ts +32 -0
- package/dist/rpc/index.js +19 -0
- package/dist/rpc/index.js.map +1 -0
- package/dist/rpc/index.mjs +1 -0
- package/dist/rpc/index.mjs.map +1 -0
- package/dist/runtime/index.d.mts +55 -0
- package/dist/runtime/index.d.ts +55 -0
- package/dist/runtime/index.js +15 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/index.mjs +15 -0
- package/dist/runtime/index.mjs.map +1 -0
- package/dist/server/index.d.mts +7 -0
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.js +58 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/index.mjs +58 -0
- package/dist/server/index.mjs.map +1 -0
- package/dist/types/index.d.mts +12 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types-CQ_aexOX.d.mts +32 -0
- package/dist/types-CQ_aexOX.d.ts +32 -0
- package/dist/vercel-builder/index.d.mts +58 -0
- package/dist/vercel-builder/index.d.ts +58 -0
- package/dist/vercel-builder/index.js +330 -0
- package/dist/vercel-builder/index.js.map +1 -0
- package/dist/vercel-builder/index.mjs +330 -0
- package/dist/vercel-builder/index.mjs.map +1 -0
- package/package.json +153 -153
- package/templates/.dockerignore +43 -43
- package/templates/.env.example +17 -17
- package/templates/Dockerfile +60 -60
- package/templates/Procfile +1 -1
- package/templates/README.md +67 -67
- package/templates/api-sdk.ts +115 -115
- package/templates/docker-compose.yml +34 -34
- package/templates/nestjs-api/.env.example +3 -3
- package/templates/nestjs-api/README.md +87 -87
- package/templates/nestjs-api/nest-cli.json +6 -6
- package/templates/nestjs-api/package.json +40 -40
- package/templates/nestjs-api/prisma/migrations/20251123205437_init/migration.sql +24 -24
- package/templates/nestjs-api/prisma/migrations/migration_lock.toml +3 -3
- package/templates/nestjs-api/prisma/schema.prisma +29 -29
- package/templates/nestjs-api/src/app.module.ts +19 -17
- package/templates/nestjs-api/src/auth/auth.controller.ts +27 -27
- package/templates/nestjs-api/src/auth/auth.module.ts +37 -37
- package/templates/nestjs-api/src/auth/auth.service.ts +86 -86
- package/templates/nestjs-api/src/auth/dto/auth.dto.ts +22 -22
- package/templates/nestjs-api/src/auth/guards/jwt-auth.guard.ts +5 -5
- package/templates/nestjs-api/src/auth/strategies/jwt.strategy.ts +27 -27
- package/templates/nestjs-api/src/hello.service.ts +11 -0
- package/templates/nestjs-api/src/main.ts +32 -32
- package/templates/nestjs-api/src/prisma/prisma.module.ts +9 -9
- package/templates/nestjs-api/src/prisma/prisma.service.ts +14 -14
- package/templates/nestjs-api/src/todos/dto/todo.dto.ts +24 -24
- package/templates/nestjs-api/src/todos/todos.controller.ts +39 -39
- package/templates/nestjs-api/src/todos/todos.module.ts +11 -11
- package/templates/nestjs-api/src/todos/todos.service.ts +53 -53
- package/templates/nestjs-api/src/users/users.controller.ts +14 -14
- package/templates/nestjs-api/src/users/users.module.ts +12 -12
- package/templates/nestjs-api/src/users/users.service.ts +19 -19
- package/templates/nestjs-api/tsconfig.json +39 -39
- package/templates/nextjs-web/README.md +76 -76
- package/templates/nextjs-web/app/actions/auth.ts +108 -108
- package/templates/nextjs-web/app/dashboard/error.tsx +39 -39
- package/templates/nextjs-web/app/dashboard/loading.tsx +14 -14
- package/templates/nextjs-web/app/dashboard/page.tsx +5 -5
- package/templates/nextjs-web/app/globals.css +93 -93
- package/templates/nextjs-web/app/layout.tsx +29 -29
- package/templates/nextjs-web/app/login/page.tsx +5 -5
- package/templates/nextjs-web/app/page.tsx +138 -28
- package/templates/nextjs-web/app/register/page.tsx +5 -5
- package/templates/nextjs-web/components/ui/button.tsx +56 -56
- package/templates/nextjs-web/components/ui/card.tsx +79 -79
- package/templates/nextjs-web/components/ui/input.tsx +25 -25
- package/templates/nextjs-web/components/ui/label.tsx +24 -24
- package/templates/nextjs-web/features/auth/LoginForm.tsx +140 -140
- package/templates/nextjs-web/features/auth/RegisterForm.tsx +159 -159
- package/templates/nextjs-web/features/auth/api.ts +35 -35
- package/templates/nextjs-web/features/auth/index.ts +3 -3
- package/templates/nextjs-web/features/dashboard/DashboardView.tsx +204 -204
- package/templates/nextjs-web/features/dashboard/api.ts +9 -9
- package/templates/nextjs-web/features/dashboard/components.tsx +74 -74
- package/templates/nextjs-web/features/dashboard/index.ts +3 -3
- package/templates/nextjs-web/hooks/index.ts +4 -4
- package/templates/nextjs-web/lib/api-client.ts +89 -89
- package/templates/nextjs-web/lib/api.ts +115 -115
- package/templates/nextjs-web/lib/axios-global-config.ts +17 -17
- package/templates/nextjs-web/lib/utils.ts +6 -6
- package/templates/nextjs-web/lib/wexts-client.ts +4 -4
- package/templates/nextjs-web/next-env.d.ts +6 -6
- package/templates/nextjs-web/next.config.ts +20 -20
- package/templates/nextjs-web/package.json +37 -37
- package/templates/nextjs-web/postcss.config.js +6 -6
- package/templates/nextjs-web/tailwind.config.ts +69 -69
- package/templates/nextjs-web/tsconfig.json +41 -41
- package/templates/nixpacks.toml +11 -11
- package/templates/root-package.json +31 -31
- package/templates/server.ts +66 -66
- package/templates/tsconfig.json +30 -30
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "wexts-api",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "wexts NestJS API",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"build": "nest build",
|
|
7
|
-
"dev": "nest start --watch",
|
|
8
|
-
"start": "nest start",
|
|
9
|
-
"start:dev": "nest start --watch",
|
|
10
|
-
"start:prod": "node dist/main",
|
|
11
|
-
"prisma:generate": "prisma generate",
|
|
12
|
-
"prisma:migrate": "prisma migrate dev",
|
|
13
|
-
"prisma:studio": "prisma studio"
|
|
14
|
-
},
|
|
15
|
-
"dependencies": {
|
|
16
|
-
"@nestjs/common": "^11.0.0",
|
|
17
|
-
"@nestjs/config": "^4.0.2",
|
|
18
|
-
"@nestjs/core": "^11.0.0",
|
|
19
|
-
"@nestjs/jwt": "^11.0.0",
|
|
20
|
-
"@nestjs/passport": "^11.0.0",
|
|
21
|
-
"@nestjs/platform-fastify": "^11.0.0",
|
|
22
|
-
"@prisma/client": "^6.0.0",
|
|
23
|
-
"bcrypt": "^5.1.1",
|
|
24
|
-
"class-transformer": "^0.5.1",
|
|
25
|
-
"class-validator": "^0.14.1",
|
|
26
|
-
"passport": "^0.7.0",
|
|
27
|
-
"passport-jwt": "^4.0.1",
|
|
28
|
-
"reflect-metadata": "^0.2.2",
|
|
29
|
-
"rxjs": "^7.8.1",
|
|
30
|
-
"wexts": "^2.0.0"
|
|
31
|
-
},
|
|
32
|
-
"devDependencies": {
|
|
33
|
-
"@nestjs/cli": "^11.0.0",
|
|
34
|
-
"@nestjs/schematics": "^11.0.0",
|
|
35
|
-
"@types/bcrypt": "^5.0.2",
|
|
36
|
-
"@types/node": "^22.0.0",
|
|
37
|
-
"@types/passport-jwt": "^4.0.1",
|
|
38
|
-
"prisma": "^6.0.0",
|
|
39
|
-
"typescript": "^5.9.3"
|
|
40
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "wexts-api",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "wexts NestJS API",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "nest build",
|
|
7
|
+
"dev": "nest start --watch",
|
|
8
|
+
"start": "nest start",
|
|
9
|
+
"start:dev": "nest start --watch",
|
|
10
|
+
"start:prod": "node dist/main",
|
|
11
|
+
"prisma:generate": "prisma generate",
|
|
12
|
+
"prisma:migrate": "prisma migrate dev",
|
|
13
|
+
"prisma:studio": "prisma studio"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@nestjs/common": "^11.0.0",
|
|
17
|
+
"@nestjs/config": "^4.0.2",
|
|
18
|
+
"@nestjs/core": "^11.0.0",
|
|
19
|
+
"@nestjs/jwt": "^11.0.0",
|
|
20
|
+
"@nestjs/passport": "^11.0.0",
|
|
21
|
+
"@nestjs/platform-fastify": "^11.0.0",
|
|
22
|
+
"@prisma/client": "^6.0.0",
|
|
23
|
+
"bcrypt": "^5.1.1",
|
|
24
|
+
"class-transformer": "^0.5.1",
|
|
25
|
+
"class-validator": "^0.14.1",
|
|
26
|
+
"passport": "^0.7.0",
|
|
27
|
+
"passport-jwt": "^4.0.1",
|
|
28
|
+
"reflect-metadata": "^0.2.2",
|
|
29
|
+
"rxjs": "^7.8.1",
|
|
30
|
+
"wexts": "^2.0.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@nestjs/cli": "^11.0.0",
|
|
34
|
+
"@nestjs/schematics": "^11.0.0",
|
|
35
|
+
"@types/bcrypt": "^5.0.2",
|
|
36
|
+
"@types/node": "^22.0.0",
|
|
37
|
+
"@types/passport-jwt": "^4.0.1",
|
|
38
|
+
"prisma": "^6.0.0",
|
|
39
|
+
"typescript": "^5.9.3"
|
|
40
|
+
}
|
|
41
41
|
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
-- CreateTable
|
|
2
|
-
CREATE TABLE "User" (
|
|
3
|
-
"id" TEXT NOT NULL PRIMARY KEY,
|
|
4
|
-
"email" TEXT NOT NULL,
|
|
5
|
-
"name" TEXT,
|
|
6
|
-
"password" TEXT NOT NULL,
|
|
7
|
-
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
8
|
-
"updatedAt" DATETIME NOT NULL
|
|
9
|
-
);
|
|
10
|
-
|
|
11
|
-
-- CreateTable
|
|
12
|
-
CREATE TABLE "Todo" (
|
|
13
|
-
"id" TEXT NOT NULL PRIMARY KEY,
|
|
14
|
-
"title" TEXT NOT NULL,
|
|
15
|
-
"description" TEXT,
|
|
16
|
-
"completed" BOOLEAN NOT NULL DEFAULT false,
|
|
17
|
-
"userId" TEXT NOT NULL,
|
|
18
|
-
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
19
|
-
"updatedAt" DATETIME NOT NULL,
|
|
20
|
-
CONSTRAINT "Todo_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
-- CreateIndex
|
|
24
|
-
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
|
|
1
|
+
-- CreateTable
|
|
2
|
+
CREATE TABLE "User" (
|
|
3
|
+
"id" TEXT NOT NULL PRIMARY KEY,
|
|
4
|
+
"email" TEXT NOT NULL,
|
|
5
|
+
"name" TEXT,
|
|
6
|
+
"password" TEXT NOT NULL,
|
|
7
|
+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
8
|
+
"updatedAt" DATETIME NOT NULL
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
-- CreateTable
|
|
12
|
+
CREATE TABLE "Todo" (
|
|
13
|
+
"id" TEXT NOT NULL PRIMARY KEY,
|
|
14
|
+
"title" TEXT NOT NULL,
|
|
15
|
+
"description" TEXT,
|
|
16
|
+
"completed" BOOLEAN NOT NULL DEFAULT false,
|
|
17
|
+
"userId" TEXT NOT NULL,
|
|
18
|
+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
19
|
+
"updatedAt" DATETIME NOT NULL,
|
|
20
|
+
CONSTRAINT "Todo_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
-- CreateIndex
|
|
24
|
+
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
# Please do not edit this file manually
|
|
2
|
-
# It should be added in your version-control system (e.g., Git)
|
|
3
|
-
provider = "sqlite"
|
|
1
|
+
# Please do not edit this file manually
|
|
2
|
+
# It should be added in your version-control system (e.g., Git)
|
|
3
|
+
provider = "sqlite"
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
generator client {
|
|
2
|
-
provider = "prisma-client-js"
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
datasource db {
|
|
6
|
-
provider = "sqlite"
|
|
7
|
-
url = env("DATABASE_URL")
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
model User {
|
|
11
|
-
id String @id @default(uuid())
|
|
12
|
-
email String @unique
|
|
13
|
-
name String?
|
|
14
|
-
password String
|
|
15
|
-
createdAt DateTime @default(now())
|
|
16
|
-
updatedAt DateTime @updatedAt
|
|
17
|
-
todos Todo[]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
model Todo {
|
|
21
|
-
id String @id @default(uuid())
|
|
22
|
-
title String
|
|
23
|
-
description String?
|
|
24
|
-
completed Boolean @default(false)
|
|
25
|
-
userId String
|
|
26
|
-
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
27
|
-
createdAt DateTime @default(now())
|
|
28
|
-
updatedAt DateTime @updatedAt
|
|
29
|
-
}
|
|
1
|
+
generator client {
|
|
2
|
+
provider = "prisma-client-js"
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
datasource db {
|
|
6
|
+
provider = "sqlite"
|
|
7
|
+
url = env("DATABASE_URL")
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
model User {
|
|
11
|
+
id String @id @default(uuid())
|
|
12
|
+
email String @unique
|
|
13
|
+
name String?
|
|
14
|
+
password String
|
|
15
|
+
createdAt DateTime @default(now())
|
|
16
|
+
updatedAt DateTime @updatedAt
|
|
17
|
+
todos Todo[]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
model Todo {
|
|
21
|
+
id String @id @default(uuid())
|
|
22
|
+
title String
|
|
23
|
+
description String?
|
|
24
|
+
completed Boolean @default(false)
|
|
25
|
+
userId String
|
|
26
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
27
|
+
createdAt DateTime @default(now())
|
|
28
|
+
updatedAt DateTime @updatedAt
|
|
29
|
+
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import { Module } from '@nestjs/common';
|
|
2
|
-
import { ConfigModule } from '@nestjs/config';
|
|
3
|
-
import { PrismaModule } from './prisma/prisma.module';
|
|
4
|
-
import { AuthModule } from './auth/auth.module';
|
|
5
|
-
import { UsersModule } from './users/users.module';
|
|
6
|
-
import { TodosModule } from './todos/todos.module';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import { Module } from '@nestjs/common';
|
|
2
|
+
import { ConfigModule } from '@nestjs/config';
|
|
3
|
+
import { PrismaModule } from './prisma/prisma.module';
|
|
4
|
+
import { AuthModule } from './auth/auth.module';
|
|
5
|
+
import { UsersModule } from './users/users.module';
|
|
6
|
+
import { TodosModule } from './todos/todos.module';
|
|
7
|
+
import { HelloService } from './hello.service';
|
|
8
|
+
|
|
9
|
+
@Module({
|
|
10
|
+
imports: [
|
|
11
|
+
ConfigModule.forRoot({ isGlobal: true }),
|
|
12
|
+
PrismaModule,
|
|
13
|
+
AuthModule,
|
|
14
|
+
UsersModule,
|
|
15
|
+
TodosModule,
|
|
16
|
+
],
|
|
17
|
+
providers: [HelloService],
|
|
18
|
+
})
|
|
19
|
+
export class AppModule { }
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { Controller, Post, Get, Body, UseGuards, Request, Inject } from '@nestjs/common';
|
|
2
|
-
import { AuthService } from './auth.service';
|
|
3
|
-
import { JwtAuthGuard } from './guards/jwt-auth.guard';
|
|
4
|
-
import { RegisterDto, LoginDto } from './dto/auth.dto';
|
|
5
|
-
|
|
6
|
-
@Controller('auth')
|
|
7
|
-
export class AuthController {
|
|
8
|
-
constructor(
|
|
9
|
-
@Inject(AuthService) private readonly authService: AuthService
|
|
10
|
-
) { }
|
|
11
|
-
|
|
12
|
-
@Post('register')
|
|
13
|
-
async register(@Body() dto: RegisterDto) {
|
|
14
|
-
return this.authService.register(dto);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
@Post('login')
|
|
18
|
-
async login(@Body() dto: LoginDto) {
|
|
19
|
-
return this.authService.login(dto);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@Get('me')
|
|
23
|
-
@UseGuards(JwtAuthGuard)
|
|
24
|
-
async getMe(@Request() req) {
|
|
25
|
-
return this.authService.getMe(req.user.userId);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
1
|
+
import { Controller, Post, Get, Body, UseGuards, Request, Inject } from '@nestjs/common';
|
|
2
|
+
import { AuthService } from './auth.service';
|
|
3
|
+
import { JwtAuthGuard } from './guards/jwt-auth.guard';
|
|
4
|
+
import { RegisterDto, LoginDto } from './dto/auth.dto';
|
|
5
|
+
|
|
6
|
+
@Controller('auth')
|
|
7
|
+
export class AuthController {
|
|
8
|
+
constructor(
|
|
9
|
+
@Inject(AuthService) private readonly authService: AuthService
|
|
10
|
+
) { }
|
|
11
|
+
|
|
12
|
+
@Post('register')
|
|
13
|
+
async register(@Body() dto: RegisterDto) {
|
|
14
|
+
return this.authService.register(dto);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@Post('login')
|
|
18
|
+
async login(@Body() dto: LoginDto) {
|
|
19
|
+
return this.authService.login(dto);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@Get('me')
|
|
23
|
+
@UseGuards(JwtAuthGuard)
|
|
24
|
+
async getMe(@Request() req) {
|
|
25
|
+
return this.authService.getMe(req.user.userId);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { Module } from '@nestjs/common';
|
|
2
|
-
import { JwtModule } from '@nestjs/jwt';
|
|
3
|
-
import { PassportModule } from '@nestjs/passport';
|
|
4
|
-
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
5
|
-
import { AuthController } from './auth.controller';
|
|
6
|
-
import { AuthService } from './auth.service';
|
|
7
|
-
import { JwtStrategy } from './strategies/jwt.strategy';
|
|
8
|
-
import { PrismaModule } from '../prisma/prisma.module';
|
|
9
|
-
|
|
10
|
-
@Module({
|
|
11
|
-
imports: [
|
|
12
|
-
PrismaModule, // ✅ Important: Import PrismaModule
|
|
13
|
-
ConfigModule,
|
|
14
|
-
PassportModule,
|
|
15
|
-
JwtModule.registerAsync({
|
|
16
|
-
inject: [ConfigService],
|
|
17
|
-
useFactory: (config: ConfigService) => ({
|
|
18
|
-
secret: getJwtSecret(config),
|
|
19
|
-
signOptions: {
|
|
20
|
-
expiresIn: config.get('JWT_EXPIRES_IN') || '7d',
|
|
21
|
-
},
|
|
22
|
-
}),
|
|
23
|
-
}),
|
|
24
|
-
],
|
|
25
|
-
controllers: [AuthController],
|
|
26
|
-
providers: [AuthService, JwtStrategy],
|
|
27
|
-
exports: [AuthService],
|
|
28
|
-
})
|
|
29
|
-
export class AuthModule { }
|
|
30
|
-
|
|
31
|
-
function getJwtSecret(config: ConfigService): string {
|
|
32
|
-
const secret = config.get<string>('JWT_SECRET');
|
|
33
|
-
if (!secret || secret.length < 32) {
|
|
34
|
-
throw new Error('JWT_SECRET must be set to at least 32 characters.');
|
|
35
|
-
}
|
|
36
|
-
return secret;
|
|
37
|
-
}
|
|
1
|
+
import { Module } from '@nestjs/common';
|
|
2
|
+
import { JwtModule } from '@nestjs/jwt';
|
|
3
|
+
import { PassportModule } from '@nestjs/passport';
|
|
4
|
+
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
5
|
+
import { AuthController } from './auth.controller';
|
|
6
|
+
import { AuthService } from './auth.service';
|
|
7
|
+
import { JwtStrategy } from './strategies/jwt.strategy';
|
|
8
|
+
import { PrismaModule } from '../prisma/prisma.module';
|
|
9
|
+
|
|
10
|
+
@Module({
|
|
11
|
+
imports: [
|
|
12
|
+
PrismaModule, // ✅ Important: Import PrismaModule
|
|
13
|
+
ConfigModule,
|
|
14
|
+
PassportModule,
|
|
15
|
+
JwtModule.registerAsync({
|
|
16
|
+
inject: [ConfigService],
|
|
17
|
+
useFactory: (config: ConfigService) => ({
|
|
18
|
+
secret: getJwtSecret(config),
|
|
19
|
+
signOptions: {
|
|
20
|
+
expiresIn: config.get('JWT_EXPIRES_IN') || '7d',
|
|
21
|
+
},
|
|
22
|
+
}),
|
|
23
|
+
}),
|
|
24
|
+
],
|
|
25
|
+
controllers: [AuthController],
|
|
26
|
+
providers: [AuthService, JwtStrategy],
|
|
27
|
+
exports: [AuthService],
|
|
28
|
+
})
|
|
29
|
+
export class AuthModule { }
|
|
30
|
+
|
|
31
|
+
function getJwtSecret(config: ConfigService): string {
|
|
32
|
+
const secret = config.get<string>('JWT_SECRET');
|
|
33
|
+
if (!secret || secret.length < 32) {
|
|
34
|
+
throw new Error('JWT_SECRET must be set to at least 32 characters.');
|
|
35
|
+
}
|
|
36
|
+
return secret;
|
|
37
|
+
}
|
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
import { Injectable, UnauthorizedException, Inject } from '@nestjs/common';
|
|
2
|
-
import { JwtService } from '@nestjs/jwt';
|
|
3
|
-
import { PrismaService } from '../prisma/prisma.service';
|
|
4
|
-
import * as bcrypt from 'bcryptjs';
|
|
5
|
-
import { RegisterDto, LoginDto } from './dto/auth.dto';
|
|
6
|
-
|
|
7
|
-
@Injectable()
|
|
8
|
-
export class AuthService {
|
|
9
|
-
constructor(
|
|
10
|
-
@Inject(PrismaService) private readonly prisma: PrismaService,
|
|
11
|
-
@Inject(JwtService) private readonly jwtService: JwtService,
|
|
12
|
-
) { }
|
|
13
|
-
|
|
14
|
-
async register(dto: RegisterDto) {
|
|
15
|
-
const exists = await this.prisma.user.findUnique({
|
|
16
|
-
where: { email: dto.email },
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
if (exists) {
|
|
20
|
-
throw new UnauthorizedException('Email already registered');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const hashedPassword = await bcrypt.hash(dto.password, 10);
|
|
24
|
-
|
|
25
|
-
const user = await this.prisma.user.create({
|
|
26
|
-
data: {
|
|
27
|
-
email: dto.email,
|
|
28
|
-
name: dto.name,
|
|
29
|
-
password: hashedPassword,
|
|
30
|
-
},
|
|
31
|
-
select: {
|
|
32
|
-
id: true,
|
|
33
|
-
email: true,
|
|
34
|
-
name: true,
|
|
35
|
-
createdAt: true,
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const access_token = this.generateToken(user.id, user.email);
|
|
40
|
-
|
|
41
|
-
return { user, access_token };
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async login(dto: LoginDto) {
|
|
45
|
-
const user = await this.prisma.user.findUnique({
|
|
46
|
-
where: { email: dto.email },
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
if (!user) {
|
|
50
|
-
throw new UnauthorizedException('Invalid credentials');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const valid = await bcrypt.compare(dto.password, user.password);
|
|
54
|
-
|
|
55
|
-
if (!valid) {
|
|
56
|
-
throw new UnauthorizedException('Invalid credentials');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const access_token = this.generateToken(user.id, user.email);
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
user: {
|
|
63
|
-
id: user.id,
|
|
64
|
-
email: user.email,
|
|
65
|
-
name: user.name,
|
|
66
|
-
},
|
|
67
|
-
access_token,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async getMe(userId: string) {
|
|
72
|
-
return this.prisma.user.findUnique({
|
|
73
|
-
where: { id: userId },
|
|
74
|
-
select: {
|
|
75
|
-
id: true,
|
|
76
|
-
email: true,
|
|
77
|
-
name: true,
|
|
78
|
-
createdAt: true,
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
private generateToken(userId: string, email: string): string {
|
|
84
|
-
return this.jwtService.sign({ sub: userId, email });
|
|
85
|
-
}
|
|
86
|
-
}
|
|
1
|
+
import { Injectable, UnauthorizedException, Inject } from '@nestjs/common';
|
|
2
|
+
import { JwtService } from '@nestjs/jwt';
|
|
3
|
+
import { PrismaService } from '../prisma/prisma.service';
|
|
4
|
+
import * as bcrypt from 'bcryptjs';
|
|
5
|
+
import { RegisterDto, LoginDto } from './dto/auth.dto';
|
|
6
|
+
|
|
7
|
+
@Injectable()
|
|
8
|
+
export class AuthService {
|
|
9
|
+
constructor(
|
|
10
|
+
@Inject(PrismaService) private readonly prisma: PrismaService,
|
|
11
|
+
@Inject(JwtService) private readonly jwtService: JwtService,
|
|
12
|
+
) { }
|
|
13
|
+
|
|
14
|
+
async register(dto: RegisterDto) {
|
|
15
|
+
const exists = await this.prisma.user.findUnique({
|
|
16
|
+
where: { email: dto.email },
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
if (exists) {
|
|
20
|
+
throw new UnauthorizedException('Email already registered');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const hashedPassword = await bcrypt.hash(dto.password, 10);
|
|
24
|
+
|
|
25
|
+
const user = await this.prisma.user.create({
|
|
26
|
+
data: {
|
|
27
|
+
email: dto.email,
|
|
28
|
+
name: dto.name,
|
|
29
|
+
password: hashedPassword,
|
|
30
|
+
},
|
|
31
|
+
select: {
|
|
32
|
+
id: true,
|
|
33
|
+
email: true,
|
|
34
|
+
name: true,
|
|
35
|
+
createdAt: true,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const access_token = this.generateToken(user.id, user.email);
|
|
40
|
+
|
|
41
|
+
return { user, access_token };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async login(dto: LoginDto) {
|
|
45
|
+
const user = await this.prisma.user.findUnique({
|
|
46
|
+
where: { email: dto.email },
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if (!user) {
|
|
50
|
+
throw new UnauthorizedException('Invalid credentials');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const valid = await bcrypt.compare(dto.password, user.password);
|
|
54
|
+
|
|
55
|
+
if (!valid) {
|
|
56
|
+
throw new UnauthorizedException('Invalid credentials');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const access_token = this.generateToken(user.id, user.email);
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
user: {
|
|
63
|
+
id: user.id,
|
|
64
|
+
email: user.email,
|
|
65
|
+
name: user.name,
|
|
66
|
+
},
|
|
67
|
+
access_token,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async getMe(userId: string) {
|
|
72
|
+
return this.prisma.user.findUnique({
|
|
73
|
+
where: { id: userId },
|
|
74
|
+
select: {
|
|
75
|
+
id: true,
|
|
76
|
+
email: true,
|
|
77
|
+
name: true,
|
|
78
|
+
createdAt: true,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private generateToken(userId: string, email: string): string {
|
|
84
|
+
return this.jwtService.sign({ sub: userId, email });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { IsEmail, IsString, MinLength, IsOptional } from 'class-validator';
|
|
2
|
-
|
|
3
|
-
export class RegisterDto {
|
|
4
|
-
@IsEmail()
|
|
5
|
-
email: string;
|
|
6
|
-
|
|
7
|
-
@IsString()
|
|
8
|
-
@MinLength(6)
|
|
9
|
-
password: string;
|
|
10
|
-
|
|
11
|
-
@IsString()
|
|
12
|
-
@IsOptional()
|
|
13
|
-
name?: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class LoginDto {
|
|
17
|
-
@IsEmail()
|
|
18
|
-
email: string;
|
|
19
|
-
|
|
20
|
-
@IsString()
|
|
21
|
-
password: string;
|
|
22
|
-
}
|
|
1
|
+
import { IsEmail, IsString, MinLength, IsOptional } from 'class-validator';
|
|
2
|
+
|
|
3
|
+
export class RegisterDto {
|
|
4
|
+
@IsEmail()
|
|
5
|
+
email: string;
|
|
6
|
+
|
|
7
|
+
@IsString()
|
|
8
|
+
@MinLength(6)
|
|
9
|
+
password: string;
|
|
10
|
+
|
|
11
|
+
@IsString()
|
|
12
|
+
@IsOptional()
|
|
13
|
+
name?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class LoginDto {
|
|
17
|
+
@IsEmail()
|
|
18
|
+
email: string;
|
|
19
|
+
|
|
20
|
+
@IsString()
|
|
21
|
+
password: string;
|
|
22
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import { AuthGuard } from '@nestjs/passport';
|
|
3
|
-
|
|
4
|
-
@Injectable()
|
|
5
|
-
export class JwtAuthGuard extends AuthGuard('jwt') { }
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { AuthGuard } from '@nestjs/passport';
|
|
3
|
+
|
|
4
|
+
@Injectable()
|
|
5
|
+
export class JwtAuthGuard extends AuthGuard('jwt') { }
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { ExtractJwt, Strategy } from 'passport-jwt';
|
|
2
|
-
import { PassportStrategy } from '@nestjs/passport';
|
|
3
|
-
import { Injectable } from '@nestjs/common';
|
|
4
|
-
import { ConfigService } from '@nestjs/config';
|
|
5
|
-
|
|
6
|
-
@Injectable()
|
|
7
|
-
export class JwtStrategy extends PassportStrategy(Strategy) {
|
|
8
|
-
constructor(configService: ConfigService) {
|
|
9
|
-
super({
|
|
10
|
-
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
11
|
-
ignoreExpiration: false,
|
|
12
|
-
secretOrKey: getJwtSecret(configService),
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async validate(payload: any) {
|
|
17
|
-
return { userId: payload.sub, email: payload.email };
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function getJwtSecret(configService: ConfigService): string {
|
|
22
|
-
const secret = configService.get<string>('JWT_SECRET');
|
|
23
|
-
if (!secret || secret.length < 32) {
|
|
24
|
-
throw new Error('JWT_SECRET must be set to at least 32 characters.');
|
|
25
|
-
}
|
|
26
|
-
return secret;
|
|
27
|
-
}
|
|
1
|
+
import { ExtractJwt, Strategy } from 'passport-jwt';
|
|
2
|
+
import { PassportStrategy } from '@nestjs/passport';
|
|
3
|
+
import { Injectable } from '@nestjs/common';
|
|
4
|
+
import { ConfigService } from '@nestjs/config';
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class JwtStrategy extends PassportStrategy(Strategy) {
|
|
8
|
+
constructor(configService: ConfigService) {
|
|
9
|
+
super({
|
|
10
|
+
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
11
|
+
ignoreExpiration: false,
|
|
12
|
+
secretOrKey: getJwtSecret(configService),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async validate(payload: any) {
|
|
17
|
+
return { userId: payload.sub, email: payload.email };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getJwtSecret(configService: ConfigService): string {
|
|
22
|
+
const secret = configService.get<string>('JWT_SECRET');
|
|
23
|
+
if (!secret || secret.length < 32) {
|
|
24
|
+
throw new Error('JWT_SECRET must be set to at least 32 characters.');
|
|
25
|
+
}
|
|
26
|
+
return secret;
|
|
27
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { RpcMethod, RpcService } from 'wexts/nest';
|
|
3
|
+
|
|
4
|
+
@Injectable()
|
|
5
|
+
@RpcService({ name: 'hello', requireAuth: false })
|
|
6
|
+
export class HelloService {
|
|
7
|
+
@RpcMethod()
|
|
8
|
+
async sayHello(name: string): Promise<string> {
|
|
9
|
+
return `Hello, ${name} from RPC!`;
|
|
10
|
+
}
|
|
11
|
+
}
|