@urga-panel/ur-panels-core 1.0.16 → 1.0.18

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.
@@ -54,11 +54,12 @@ export declare abstract class AuthService extends Service {
54
54
  request: any;
55
55
  url: any;
56
56
  }): Promise<any>;
57
- checkToken({ panel_token, options }: {
57
+ checkToken({ panel_token, options, auth_token }: {
58
58
  panel_token: string;
59
59
  options?: {
60
60
  role?: string;
61
61
  };
62
+ auth_token: string;
62
63
  }): Promise<{
63
64
  valid: boolean;
64
65
  newPanelToken?: string;
@@ -135,7 +135,7 @@ export class AuthService extends Service {
135
135
  return this.resposeHandler({ status: "error", message: "An error occurred during login" });
136
136
  }
137
137
  }
138
- async checkToken({ panel_token, options }) {
138
+ async checkToken({ panel_token, options, auth_token }) {
139
139
  this.log.OK("panel_token Token:", panel_token);
140
140
  //debugger;
141
141
  try {
@@ -144,6 +144,23 @@ export class AuthService extends Service {
144
144
  if (typeof window === "undefined") {
145
145
  jwt = (await import("jsonwebtoken")).default;
146
146
  }
147
+ if (panel_token === undefined || panel_token === "") {
148
+ if (auth_token === undefined || auth_token === "") {
149
+ return { valid: false };
150
+ }
151
+ else {
152
+ const decoded = jwt.verify(auth_token, JWT_REFRESH_SECRET);
153
+ const res = await this.getUserInfo({
154
+ userId: decoded.id,
155
+ userName: decoded.username,
156
+ userRole: decoded.role || "user",
157
+ userEmail: decoded.email
158
+ });
159
+ if (res.success) {
160
+ return { valid: true, user: res.user };
161
+ }
162
+ }
163
+ }
147
164
  const decoded = jwt.verify(panel_token, JWT_SECRET);
148
165
  const res = await this.getUserInfo({
149
166
  userId: decoded.id,
@@ -16,6 +16,7 @@ export type ProjectsPages = {
16
16
  service?: PageService;
17
17
  serviceRef: any;
18
18
  userGroup?: string;
19
+ onlyForGroup?: boolean;
19
20
  };
20
21
  };
21
22
  export type ProjectInfoOts = ServiceOts & {
@@ -45,7 +45,10 @@ export class ProjectInfoService extends Service {
45
45
  Object.entries(this.pages).forEach(([key, page]) => {
46
46
  if (page.showInMenu) {
47
47
  if (userGroup && userGroup == 'admin') {
48
- result[key] = page;
48
+ // If onlyForGroup is true, admin cannot see this page
49
+ if (page.onlyForGroup !== true) {
50
+ result[key] = page;
51
+ }
49
52
  }
50
53
  else {
51
54
  if (userGroup) {
@@ -68,8 +68,10 @@ export class RequestHandlerService extends Service {
68
68
  }
69
69
  const cookieHeader = request.headers.get('cookie');
70
70
  const panel_token = this.getCookie(cookieHeader, 'panel_token');
71
+ const auth_token = this.getCookie(cookieHeader, 'auth_token');
71
72
  // Check authentication and role
72
73
  const isAuthenticated = await authService.checkToken({
74
+ auth_token,
73
75
  panel_token,
74
76
  options: {
75
77
  role: handler.options?.role
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@urga-panel/ur-panels-core",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -213,19 +213,42 @@ export abstract class AuthService extends Service {
213
213
  return this.resposeHandler({ status: "error", message: "An error occurred during login" });
214
214
  }
215
215
  }
216
- async checkToken({ panel_token, options }: {
217
- panel_token: string, options?: {
216
+ async checkToken({ panel_token, options, auth_token }: {
217
+ panel_token: string,
218
+ options?: {
218
219
  role?: string;
219
- }
220
+ },
221
+ auth_token: string
220
222
  }): Promise<{ valid: boolean; newPanelToken?: string, user?: any }> {
221
223
  this.log.OK("panel_token Token:", panel_token);
224
+
222
225
  //debugger;
223
226
  try {
224
- // 1. Access token'ı doğrula
227
+ // 1. Access token'ı doğrula
225
228
  let jwt: typeof import("jsonwebtoken") | undefined;
226
229
  if (typeof window === "undefined") {
227
230
  jwt = (await import("jsonwebtoken")).default;
228
231
  }
232
+
233
+ if (panel_token === undefined || panel_token === "") {
234
+ if (auth_token === undefined || auth_token === "") {
235
+ return { valid: false };
236
+ } else {
237
+ const decoded: any = jwt.verify(auth_token, JWT_REFRESH_SECRET);
238
+ const res = await this.getUserInfo({
239
+ userId: (decoded as any).id,
240
+ userName: (decoded as any).username,
241
+ userRole: (decoded as any).role || "user",
242
+ userEmail: (decoded as any).email
243
+ });
244
+ if (res.success) {
245
+ return { valid: true, user: res.user };
246
+ }
247
+ }
248
+ }
249
+
250
+
251
+
229
252
  const decoded: any = jwt.verify(panel_token, JWT_SECRET);
230
253
  const res = await this.getUserInfo({
231
254
  userId: (decoded as any).id,
@@ -17,6 +17,7 @@ export type ProjectsPages = {
17
17
  service?: PageService; // Optional service name for custom handling
18
18
  serviceRef: any;
19
19
  userGroup?: string; // Optional user group for access control
20
+ onlyForGroup?: boolean; // If true, only the specified userGroup can see this page (admin excluded)
20
21
  };
21
22
  }
22
23
 
@@ -85,7 +86,10 @@ export abstract class ProjectInfoService extends Service {
85
86
  Object.entries(this.pages).forEach(([key, page]) => {
86
87
  if (page.showInMenu) {
87
88
  if (userGroup && userGroup == 'admin') {
88
- result[key] = page;
89
+ // If onlyForGroup is true, admin cannot see this page
90
+ if (page.onlyForGroup !== true) {
91
+ result[key] = page;
92
+ }
89
93
  }
90
94
  else {
91
95
  if (userGroup) {
@@ -96,9 +96,12 @@ export class RequestHandlerService extends Service {
96
96
 
97
97
  const cookieHeader = request.headers.get('cookie');
98
98
  const panel_token = this.getCookie(cookieHeader, 'panel_token');
99
+ const auth_token = this.getCookie(cookieHeader, 'auth_token');
99
100
  // Check authentication and role
100
101
 
102
+
101
103
  const isAuthenticated = await authService.checkToken({
104
+ auth_token,
102
105
  panel_token,
103
106
  options: {
104
107
  role: handler.options?.role