lapeh 2.3.8 → 2.4.0

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/.env.example ADDED
@@ -0,0 +1,19 @@
1
+ PORT=8000
2
+ DATABASE_PROVIDER="postgresql"
3
+ DATABASE_URL="postgresql://sianu:12341234@localhost:5432/db_example_test?schema=public"
4
+
5
+ # Used for all encryption-related tasks in the framework (JWT, etc.)
6
+ JWT_SECRET="replace_this_with_a_secure_random_string"
7
+
8
+ # Framework Timezone
9
+ TZ="Asia/Jakarta"
10
+
11
+ # Redis Configuration (Optional)
12
+ # If REDIS_URL is not set or connection fails, the framework will automatically
13
+ # switch to an in-memory Redis mock (bundled). No installation required for development.
14
+ # REDIS_URL="redis://lapeh:12341234@localhost:6379"
15
+ # NO_REDIS="true"
16
+
17
+ # To force disable Redis and use in-memory mock even if Redis is available:
18
+ # NO_REDIS="true"
19
+
package/bin/index.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  const fs = require('fs');
4
4
  const path = require('path');
@@ -47,7 +47,9 @@ function runDev() {
47
47
  const bootstrapPath = fs.existsSync(localBootstrapPath) ? localBootstrapPath : fallbackBootstrapPath;
48
48
 
49
49
  // We execute a script that requires ts-node to run lib/bootstrap.ts
50
- execSync(`npx nodemon --watch src --watch lib --ext ts,json --exec "node -r ${tsNodePath} -r ${tsConfigPathsPath} ${bootstrapPath}"`, { stdio: 'inherit' });
50
+ // Use JSON.stringify to properly escape paths for the shell command
51
+ const cmd = `npx nodemon --watch src --watch lib --ext ts,json --exec "node -r ${JSON.stringify(tsNodePath)} -r ${JSON.stringify(tsConfigPathsPath)} ${JSON.stringify(bootstrapPath)}"`;
52
+ execSync(cmd, { stdio: 'inherit' });
51
53
  } catch (error) {
52
54
  // Ignore error
53
55
  }
@@ -157,14 +159,17 @@ function runStart() {
157
159
  }
158
160
 
159
161
  if (tsNodePath && tsConfigPathsPath) {
160
- cmd = `node -r ${tsNodePath} -r ${tsConfigPathsPath} -e "require('${bootstrapPath.replace(/\\/g, '/')}').bootstrap()"`;
162
+ const script = `require(${JSON.stringify(bootstrapPath)}).bootstrap()`;
163
+ cmd = `node -r ${JSON.stringify(tsNodePath)} -r ${JSON.stringify(tsConfigPathsPath)} -e ${JSON.stringify(script)}`;
161
164
  } else {
162
165
  // Fallback to npx if resolution fails
163
- cmd = `npx ts-node -r tsconfig-paths/register -e "require('${bootstrapPath.replace(/\\/g, '/')}').bootstrap()"`;
166
+ const script = `require(${JSON.stringify(bootstrapPath)}).bootstrap()`;
167
+ cmd = `npx ts-node -r tsconfig-paths/register -e ${JSON.stringify(script)}`;
164
168
  }
165
169
  } else {
166
170
  // JS file, run with node
167
- cmd = `node -e "require('${bootstrapPath.replace(/\\/g, '/')}').bootstrap()"`;
171
+ const script = `require(${JSON.stringify(bootstrapPath)}).bootstrap()`;
172
+ cmd = `node -e ${JSON.stringify(script)}`;
168
173
  }
169
174
 
170
175
  execSync(cmd, {
@@ -508,6 +513,12 @@ function createProject() {
508
513
  console.log('\nšŸ“‚ Copying template files...');
509
514
  copyDir(templateDir, projectDir);
510
515
 
516
+ // Rename gitignore.template to .gitignore
517
+ const gitignoreTemplate = path.join(projectDir, 'gitignore.template');
518
+ if (fs.existsSync(gitignoreTemplate)) {
519
+ fs.renameSync(gitignoreTemplate, path.join(projectDir, '.gitignore'));
520
+ }
521
+
511
522
  // Update package.json
512
523
  console.log('šŸ“ Updating package.json...');
513
524
  const packageJsonPath = path.join(projectDir, 'package.json');
@@ -0,0 +1,24 @@
1
+ version: "3.9"
2
+ services:
3
+ redis:
4
+ image: redis:7-alpine
5
+ command:
6
+ - "redis-server"
7
+ - "--appendonly"
8
+ - "yes"
9
+ - "--user"
10
+ - "default on >12341234 ~* +@all"
11
+ - "--user"
12
+ - "lapeh on >12341234 ~* +@all"
13
+ ports:
14
+ - "6379:6379"
15
+ volumes:
16
+ - redis_data:/data
17
+ healthcheck:
18
+ test: ["CMD", "redis-cli", "ping"]
19
+ interval: 10s
20
+ timeout: 5s
21
+ retries: 5
22
+
23
+ volumes:
24
+ redis_data:
@@ -0,0 +1,26 @@
1
+ import globals from "globals";
2
+ import pluginJs from "@eslint/js";
3
+ import tseslint from "typescript-eslint";
4
+
5
+ export default [
6
+ { files: ["**/*.{js,mjs,cjs,ts}"] },
7
+ { languageOptions: { globals: globals.node } },
8
+ pluginJs.configs.recommended,
9
+ ...tseslint.configs.recommended,
10
+ {
11
+ rules: {
12
+ "@typescript-eslint/no-unused-vars": [
13
+ "error",
14
+ {
15
+ "argsIgnorePattern": "^_",
16
+ "varsIgnorePattern": "^_",
17
+ "caughtErrorsIgnorePattern": "^_"
18
+ }
19
+ ],
20
+ "@typescript-eslint/no-explicit-any": "warn"
21
+ }
22
+ },
23
+ {
24
+ ignores: ["dist/", "node_modules/", "generated/", "scripts/"]
25
+ }
26
+ ];
@@ -0,0 +1,40 @@
1
+ # Node modules
2
+ node_modules
3
+ npm-debug.log
4
+ yarn-error.log
5
+ pnpm-lock.yaml
6
+
7
+ # Environment variables
8
+ .env
9
+ .env.local
10
+ .env.development
11
+ .env.test
12
+ .env.production
13
+
14
+ # Build output
15
+ dist
16
+ build
17
+ coverage
18
+
19
+ # IDEs
20
+ .vscode/sftp.json
21
+ .idea/
22
+ *.swp
23
+ *.swo
24
+ .DS_Store
25
+
26
+ # Prisma
27
+ generated/prisma
28
+ *.sqlite
29
+ *.db
30
+ *.db-journal
31
+ dev.db
32
+
33
+ # OS
34
+ Thumbs.db
35
+
36
+ # Logs
37
+ testing/*
38
+ # Logs
39
+ storage/logs/*
40
+ !storage/logs/.gitkeep
package/nodemon.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "watch": ["src", ".env"],
3
+ "ext": "ts,json",
4
+ "ignore": ["src/**/*.test.ts"],
5
+ "exec": "ts-node -r tsconfig-paths/register src/index.ts"
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lapeh",
3
- "version": "2.3.8",
3
+ "version": "2.4.0",
4
4
  "description": "Framework API Express yang siap pakai (Standardized)",
5
5
  "main": "dist/lib/bootstrap.js",
6
6
  "bin": {
@@ -21,8 +21,17 @@
21
21
  "lib",
22
22
  "prisma",
23
23
  "scripts",
24
+ "src",
25
+ "storage",
24
26
  "README.md",
25
- "LICENSE"
27
+ "LICENSE",
28
+ "tsconfig.json",
29
+ "nodemon.json",
30
+ "docker-compose.yml",
31
+ ".env.example",
32
+ "eslint.config.mjs",
33
+ "prisma.config.ts",
34
+ "gitignore.template"
26
35
  ],
27
36
  "scripts": {
28
37
  "dev": "node bin/index.js dev",
@@ -0,0 +1,15 @@
1
+ // This file was generated by Prisma, and assumes you have installed the following:
2
+ // npm install --save-dev prisma dotenv
3
+ import "dotenv/config";
4
+ import { defineConfig, env } from "prisma/config";
5
+
6
+ export default defineConfig({
7
+ schema: "prisma/schema.prisma",
8
+ migrations: {
9
+ path: "prisma/migrations",
10
+ seed: "ts-node -r tsconfig-paths/register prisma/seed.ts",
11
+ },
12
+ datasource: {
13
+ url: env("DATABASE_URL"),
14
+ },
15
+ });
@@ -0,0 +1,469 @@
1
+ import { Request, Response } from "express";
2
+ import bcrypt from "bcryptjs";
3
+ import jwt from "jsonwebtoken";
4
+ import { v4 as uuidv4 } from "uuid";
5
+ import { prisma } from "@lapeh/core/database";
6
+ import { sendError, sendFastSuccess } from "@lapeh/utils/response";
7
+ import { Validator } from "@lapeh/utils/validator";
8
+ import { getSerializer, createResponseSchema } from "@lapeh/core/serializer";
9
+
10
+ export const ACCESS_TOKEN_EXPIRES_IN_SECONDS = 7 * 24 * 60 * 60;
11
+
12
+ // --- Serializers ---
13
+
14
+ const registerSchema = {
15
+ type: "object",
16
+ properties: {
17
+ id: { type: "string" },
18
+ email: { type: "string" },
19
+ name: { type: "string" },
20
+ role: { type: "string" },
21
+ },
22
+ };
23
+
24
+ const loginSchema = {
25
+ type: "object",
26
+ properties: {
27
+ token: { type: "string" },
28
+ refreshToken: { type: "string" },
29
+ expiresIn: { type: "integer" },
30
+ expiresAt: { type: "string" },
31
+ name: { type: "string" },
32
+ role: { type: "string" },
33
+ },
34
+ };
35
+
36
+ const userProfileSchema = {
37
+ type: "object",
38
+ properties: {
39
+ id: { type: "string" },
40
+ name: { type: "string" },
41
+ email: { type: "string" },
42
+ role: { type: "string" },
43
+ avatar: { type: "string", nullable: true },
44
+ avatar_url: { type: "string", nullable: true },
45
+ email_verified_at: { type: "string", format: "date-time", nullable: true },
46
+ created_at: { type: "string", format: "date-time", nullable: true },
47
+ updated_at: { type: "string", format: "date-time", nullable: true },
48
+ },
49
+ };
50
+
51
+ const refreshTokenSchema = {
52
+ type: "object",
53
+ properties: {
54
+ token: { type: "string" },
55
+ expiresIn: { type: "integer" },
56
+ expiresAt: { type: "string" },
57
+ name: { type: "string" },
58
+ role: { type: "string" },
59
+ },
60
+ };
61
+
62
+ const registerSerializer = getSerializer(
63
+ "auth-register",
64
+ createResponseSchema(registerSchema)
65
+ );
66
+ const loginSerializer = getSerializer(
67
+ "auth-login",
68
+ createResponseSchema(loginSchema)
69
+ );
70
+ const userProfileSerializer = getSerializer(
71
+ "auth-profile",
72
+ createResponseSchema(userProfileSchema)
73
+ );
74
+ const refreshTokenSerializer = getSerializer(
75
+ "auth-refresh",
76
+ createResponseSchema(refreshTokenSchema)
77
+ );
78
+
79
+ const voidSerializer = getSerializer(
80
+ "void",
81
+ createResponseSchema({ type: "null" })
82
+ );
83
+
84
+ // --- Controllers ---
85
+
86
+ export async function register(req: Request, res: Response) {
87
+ const validator = Validator.make(req.body || {}, {
88
+ email: "required|email|unique:users,email",
89
+ name: "required|min:1",
90
+ password: "required|min:4",
91
+ confirmPassword: "required|min:4|same:password",
92
+ });
93
+
94
+ if (await validator.fails()) {
95
+ sendError(res, 422, "Validation error", validator.errors());
96
+ return;
97
+ }
98
+ const { email, name, password } = await validator.validated();
99
+ // Manual unique check removed as it is handled by validator
100
+ const hash = await bcrypt.hash(password, 10);
101
+ const user = await prisma.users.create({
102
+ data: {
103
+ email,
104
+ name,
105
+ password: hash,
106
+ uuid: uuidv4(),
107
+ created_at: new Date(),
108
+ updated_at: new Date(),
109
+ },
110
+ });
111
+
112
+ const defaultRole = await prisma.roles.findUnique({
113
+ where: { slug: "user" },
114
+ });
115
+ if (defaultRole) {
116
+ await prisma.user_roles.create({
117
+ data: {
118
+ user_id: user.id,
119
+ role_id: defaultRole.id,
120
+ created_at: new Date(),
121
+ },
122
+ });
123
+ }
124
+
125
+ sendFastSuccess(res, 200, registerSerializer, {
126
+ status: "success",
127
+ message: "Registration successful",
128
+ data: {
129
+ id: user.id.toString(),
130
+ email: user.email,
131
+ name: user.name,
132
+ role: defaultRole ? defaultRole.slug : "user",
133
+ },
134
+ });
135
+ }
136
+
137
+ export async function login(req: Request, res: Response) {
138
+ const validator = Validator.make(req.body || {}, {
139
+ email: "required|email",
140
+ password: "required|min:4",
141
+ });
142
+
143
+ if (await validator.fails()) {
144
+ sendError(res, 422, "Validation error", validator.errors());
145
+ return;
146
+ }
147
+ const { email, password } = await validator.validated();
148
+ const user = await prisma.users.findUnique({
149
+ where: { email },
150
+ include: {
151
+ user_roles: {
152
+ include: {
153
+ role: true,
154
+ },
155
+ },
156
+ },
157
+ });
158
+ if (!user) {
159
+ sendError(res, 401, "Email not registered", {
160
+ field: "email",
161
+ message: "Email is not registered, please register first",
162
+ });
163
+ return;
164
+ }
165
+ const ok = await bcrypt.compare(password, user.password);
166
+ if (!ok) {
167
+ sendError(res, 401, "Invalid credentials", {
168
+ field: "password",
169
+ message: "The password you entered is incorrect",
170
+ });
171
+ return;
172
+ }
173
+ const secret = process.env.JWT_SECRET;
174
+ if (!secret) {
175
+ sendError(res, 500, "Server misconfigured");
176
+ return;
177
+ }
178
+ const primaryUserRole =
179
+ user.user_roles && user.user_roles.length > 0 && user.user_roles[0].role
180
+ ? user.user_roles[0].role.slug
181
+ : "user";
182
+ const accessExpiresInSeconds = ACCESS_TOKEN_EXPIRES_IN_SECONDS;
183
+ const accessExpiresAt = new Date(
184
+ Date.now() + accessExpiresInSeconds * 1000
185
+ ).toISOString();
186
+ const token = jwt.sign(
187
+ { userId: user.id.toString(), role: primaryUserRole },
188
+ secret,
189
+ { expiresIn: accessExpiresInSeconds }
190
+ );
191
+ const refreshExpiresInSeconds = 30 * 24 * 60 * 60;
192
+ const refreshToken = jwt.sign(
193
+ {
194
+ userId: user.id.toString(),
195
+ role: primaryUserRole,
196
+ tokenType: "refresh",
197
+ },
198
+ secret,
199
+ { expiresIn: refreshExpiresInSeconds }
200
+ );
201
+ sendFastSuccess(res, 200, loginSerializer, {
202
+ status: "success",
203
+ message: "Login successful",
204
+ data: {
205
+ token,
206
+ refreshToken,
207
+ expiresIn: accessExpiresInSeconds,
208
+ expiresAt: accessExpiresAt,
209
+ name: user.name,
210
+ role: primaryUserRole,
211
+ },
212
+ });
213
+ }
214
+
215
+ export async function me(req: Request, res: Response) {
216
+ const payload = (req as any).user as { userId: string; role: string };
217
+ if (!payload || !payload.userId) {
218
+ sendError(res, 401, "Unauthorized");
219
+ return;
220
+ }
221
+ const user = await prisma.users.findUnique({
222
+ where: { id: BigInt(payload.userId) },
223
+ include: {
224
+ user_roles: {
225
+ include: {
226
+ role: true,
227
+ },
228
+ },
229
+ },
230
+ });
231
+ if (!user) {
232
+ sendError(res, 404, "User not found");
233
+ return;
234
+ }
235
+ const { password, remember_token, ...rest } = user as any;
236
+ sendFastSuccess(res, 200, userProfileSerializer, {
237
+ status: "success",
238
+ message: "User profile",
239
+ data: {
240
+ ...rest,
241
+ id: user.id.toString(),
242
+ role:
243
+ user.user_roles && user.user_roles.length > 0 && user.user_roles[0].role
244
+ ? user.user_roles[0].role.slug
245
+ : "user",
246
+ },
247
+ });
248
+ }
249
+
250
+ export async function logout(_req: Request, res: Response) {
251
+ // In a stateless JWT setup, logout is client-side (delete token).
252
+ // If using a whitelist/blacklist in Redis, invalidate the token here.
253
+ // For now, just return success.
254
+ sendFastSuccess(res, 200, voidSerializer, {
255
+ status: "success",
256
+ message: "Logout successful",
257
+ data: null,
258
+ });
259
+ }
260
+
261
+ export async function refreshToken(req: Request, res: Response) {
262
+ const validator = Validator.make(req.body || {}, {
263
+ refreshToken: "required|min:1",
264
+ });
265
+ if (await validator.fails()) {
266
+ sendError(res, 422, "Validation error", validator.errors());
267
+ return;
268
+ }
269
+ const secret = process.env.JWT_SECRET;
270
+ if (!secret) {
271
+ sendError(res, 500, "Server misconfigured");
272
+ return;
273
+ }
274
+ try {
275
+ const validatedData = await validator.validated();
276
+ const decoded = jwt.verify(validatedData.refreshToken, secret) as {
277
+ userId: string;
278
+ role: string;
279
+ tokenType?: string;
280
+ iat: number;
281
+ exp: number;
282
+ };
283
+ if (decoded.tokenType !== "refresh") {
284
+ sendError(res, 401, "Invalid refresh token");
285
+ return;
286
+ }
287
+ const user = await prisma.users.findUnique({
288
+ where: { id: BigInt(decoded.userId) },
289
+ include: {
290
+ user_roles: {
291
+ include: {
292
+ role: true,
293
+ },
294
+ },
295
+ },
296
+ });
297
+ if (!user) {
298
+ sendError(res, 401, "Invalid refresh token");
299
+ return;
300
+ }
301
+ const primaryUserRole =
302
+ user.user_roles && user.user_roles.length > 0 && user.user_roles[0].role
303
+ ? user.user_roles[0].role.slug
304
+ : "user";
305
+ const accessExpiresInSeconds = ACCESS_TOKEN_EXPIRES_IN_SECONDS;
306
+ const accessExpiresAt = new Date(
307
+ Date.now() + accessExpiresInSeconds * 1000
308
+ ).toISOString();
309
+ const token = jwt.sign(
310
+ { userId: user.id.toString(), role: primaryUserRole },
311
+ secret,
312
+ { expiresIn: accessExpiresInSeconds }
313
+ );
314
+ sendFastSuccess(res, 200, refreshTokenSerializer, {
315
+ status: "success",
316
+ message: "Token refreshed",
317
+ data: {
318
+ token,
319
+ expiresIn: accessExpiresInSeconds,
320
+ expiresAt: accessExpiresAt,
321
+ name: user.name,
322
+ role: primaryUserRole,
323
+ },
324
+ });
325
+ } catch {
326
+ sendError(res, 401, "Invalid refresh token");
327
+ }
328
+ }
329
+
330
+ export async function updateAvatar(req: Request, res: Response) {
331
+ const payload = (req as any).user as { userId: string; role: string };
332
+ if (!payload || !payload.userId) {
333
+ sendError(res, 401, "Unauthorized");
334
+ return;
335
+ }
336
+
337
+ const data = {
338
+ avatar: (req as any).file,
339
+ };
340
+
341
+ const validator = Validator.make(data, {
342
+ avatar: "nullable|image|mimes:jpeg,png,jpg,gif|max:2048",
343
+ });
344
+
345
+ if (await validator.fails()) {
346
+ sendError(res, 422, "Validation error", validator.errors());
347
+ return;
348
+ }
349
+
350
+ const { avatar: file } = await validator.validated();
351
+
352
+ if (!file) {
353
+ sendError(res, 400, "Avatar file is required");
354
+ return;
355
+ }
356
+ const userId = BigInt(payload.userId);
357
+ const avatar = file.filename;
358
+ const avatar_url =
359
+ process.env.AVATAR_BASE_URL || `/uploads/avatars/${file.filename}`;
360
+ const updated = await prisma.users.update({
361
+ where: { id: userId },
362
+ data: {
363
+ avatar,
364
+ avatar_url,
365
+ updated_at: new Date(),
366
+ },
367
+ });
368
+ const { password, remember_token, ...rest } = updated as any;
369
+ // Note: user_roles might not be fetched in update, so role defaults to "user" or fetched if needed.
370
+ // Ideally we should refetch or pass existing role.
371
+ // For now assuming role is preserved or handled by frontend state, but API should return it.
372
+ // Let's rely on nullable role or simple "user" fallback if not present in `updated`.
373
+ // Actually `update` returns what was updated. Relations are not included unless specified.
374
+ // For now we will return it compatible with userProfileSchema.
375
+
376
+ sendFastSuccess(res, 200, userProfileSerializer, {
377
+ status: "success",
378
+ message: "Avatar updated successfully",
379
+ data: {
380
+ ...rest,
381
+ id: updated.id.toString(),
382
+ role: payload.role, // Use role from JWT payload as it shouldn't change here
383
+ },
384
+ });
385
+ }
386
+
387
+ export async function updatePassword(req: Request, res: Response) {
388
+ const payload = (req as any).user as { userId: string; role: string };
389
+ if (!payload || !payload.userId) {
390
+ sendError(res, 401, "Unauthorized");
391
+ return;
392
+ }
393
+ const validator = Validator.make(req.body || {}, {
394
+ currentPassword: "required|min:4",
395
+ newPassword: "required|min:4",
396
+ confirmPassword: "required|min:4|same:newPassword",
397
+ });
398
+ if (await validator.fails()) {
399
+ sendError(res, 422, "Validation error", validator.errors());
400
+ return;
401
+ }
402
+ const { currentPassword, newPassword } = await validator.validated();
403
+ const user = await prisma.users.findUnique({
404
+ where: { id: BigInt(payload.userId) },
405
+ });
406
+ if (!user) {
407
+ sendError(res, 404, "User not found");
408
+ return;
409
+ }
410
+ const ok = await bcrypt.compare(currentPassword, user.password);
411
+ if (!ok) {
412
+ sendError(res, 401, "Invalid credentials", {
413
+ field: "currentPassword",
414
+ message: "Current password is incorrect",
415
+ });
416
+ return;
417
+ }
418
+ const hash = await bcrypt.hash(newPassword, 10);
419
+ await prisma.users.update({
420
+ where: { id: user.id },
421
+ data: {
422
+ password: hash,
423
+ updated_at: new Date(),
424
+ },
425
+ });
426
+ sendFastSuccess(res, 200, voidSerializer, {
427
+ status: "success",
428
+ message: "Password updated successfully",
429
+ data: null,
430
+ });
431
+ }
432
+
433
+ export async function updateProfile(req: Request, res: Response) {
434
+ const payload = (req as any).user as { userId: string; role: string };
435
+ if (!payload || !payload.userId) {
436
+ sendError(res, 401, "Unauthorized");
437
+ return;
438
+ }
439
+ const validator = Validator.make(req.body || {}, {
440
+ name: "required|min:1",
441
+ email: `required|email|unique:users,email,${payload.userId}`,
442
+ });
443
+ if (await validator.fails()) {
444
+ sendError(res, 422, "Validation error", validator.errors());
445
+ return;
446
+ }
447
+ const { name, email } = await validator.validated();
448
+ const userId = BigInt(payload.userId);
449
+ // Manual unique check removed as it is handled by validator
450
+
451
+ const updated = await prisma.users.update({
452
+ where: { id: userId },
453
+ data: {
454
+ name,
455
+ email,
456
+ updated_at: new Date(),
457
+ },
458
+ });
459
+ const { password, remember_token, ...rest } = updated as any;
460
+ sendFastSuccess(res, 200, userProfileSerializer, {
461
+ status: "success",
462
+ message: "Profile updated successfully",
463
+ data: {
464
+ ...rest,
465
+ id: updated.id.toString(),
466
+ role: payload.role, // Use role from JWT payload
467
+ },
468
+ });
469
+ }