@greatapps/common 1.1.134 → 1.1.137

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.
Files changed (24) hide show
  1. package/dist/{account-management.action-7QQCACDJ.mjs → account-management.action-GPQUKGJ4.mjs} +3 -3
  2. package/dist/{chunk-EC3T7NF6.mjs → chunk-2FMTHF5Y.mjs} +2 -2
  3. package/dist/chunk-47SDUOY2.mjs +75 -0
  4. package/dist/chunk-47SDUOY2.mjs.map +1 -0
  5. package/dist/{chunk-ICUZDG2N.mjs → chunk-4KASY4B6.mjs} +4 -4
  6. package/dist/{chunk-7MBVHKTC.mjs → chunk-5MR4OYS4.mjs} +1 -1
  7. package/dist/{chunk-QEFMNBSY.mjs → chunk-5QQ2B7R6.mjs} +4 -4
  8. package/dist/index.mjs +50 -114
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/middleware.mjs +13 -0
  11. package/dist/server.mjs +11 -11
  12. package/dist/{validate-session.action-K7RWN2GE.mjs → validate-session.action-QC2VBJ4N.mjs} +3 -3
  13. package/dist/validate-session.action-QC2VBJ4N.mjs.map +1 -0
  14. package/dist/{verify-two-factor.action-V6JQATK2.mjs → verify-two-factor.action-BAKUOXIH.mjs} +3 -3
  15. package/package.json +5 -1
  16. package/src/index.ts +0 -1
  17. package/src/middleware.ts +4 -0
  18. /package/dist/{account-management.action-7QQCACDJ.mjs.map → account-management.action-GPQUKGJ4.mjs.map} +0 -0
  19. /package/dist/{chunk-EC3T7NF6.mjs.map → chunk-2FMTHF5Y.mjs.map} +0 -0
  20. /package/dist/{chunk-ICUZDG2N.mjs.map → chunk-4KASY4B6.mjs.map} +0 -0
  21. /package/dist/{chunk-7MBVHKTC.mjs.map → chunk-5MR4OYS4.mjs.map} +0 -0
  22. /package/dist/{chunk-QEFMNBSY.mjs.map → chunk-5QQ2B7R6.mjs.map} +0 -0
  23. /package/dist/{validate-session.action-K7RWN2GE.mjs.map → middleware.mjs.map} +0 -0
  24. /package/dist/{verify-two-factor.action-V6JQATK2.mjs.map → verify-two-factor.action-BAKUOXIH.mjs.map} +0 -0
@@ -15,10 +15,10 @@ import {
15
15
  updateAccountAction,
16
16
  updateAccountUserByIdAction,
17
17
  updateUserAction
18
- } from "./chunk-QEFMNBSY.mjs";
19
- import "./chunk-JW4XRHLX.mjs";
18
+ } from "./chunk-5QQ2B7R6.mjs";
20
19
  import "./chunk-Z3Q2LLBS.mjs";
21
20
  import "./chunk-RV7ECGIH.mjs";
21
+ import "./chunk-JW4XRHLX.mjs";
22
22
  import "./chunk-UEWT6VFS.mjs";
23
23
  export {
24
24
  changePasswordAction,
@@ -37,4 +37,4 @@ export {
37
37
  updateAccountUserByIdAction,
38
38
  updateUserAction
39
39
  };
40
- //# sourceMappingURL=account-management.action-7QQCACDJ.mjs.map
40
+ //# sourceMappingURL=account-management.action-GPQUKGJ4.mjs.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  authService,
3
3
  getClientInfoFromRequest
4
- } from "./chunk-7MBVHKTC.mjs";
4
+ } from "./chunk-5MR4OYS4.mjs";
5
5
 
6
6
  // src/modules/auth/actions/validate-session.action.ts
7
7
  import { redirect } from "next/navigation";
@@ -47,4 +47,4 @@ async function validateSessionAction() {
47
47
  export {
48
48
  validateSessionAction
49
49
  };
50
- //# sourceMappingURL=chunk-EC3T7NF6.mjs.map
50
+ //# sourceMappingURL=chunk-2FMTHF5Y.mjs.map
@@ -0,0 +1,75 @@
1
+ // src/middlewares/types.ts
2
+ function continueChain(request) {
3
+ return { type: "next", request };
4
+ }
5
+ function stopChain(response) {
6
+ return { type: "response", response };
7
+ }
8
+
9
+ // src/middlewares/create-auth-middleware.ts
10
+ import { NextResponse } from "next/server";
11
+ function isRouteEquals(pathname, routes) {
12
+ return routes.some((route) => pathname === route || pathname.startsWith(`${route}/`));
13
+ }
14
+ function createAuthMiddleware(options) {
15
+ return (request) => {
16
+ const { pathname } = request.nextUrl;
17
+ const token = process.env.DUMMY_AUTH_TOKEN || request.cookies.get("greatapps")?.value;
18
+ const isPublicRoute = isRouteEquals(pathname, options?.publicRoutes || []);
19
+ const isAuthRoute = isRouteEquals(pathname, options?.authRoutes || []);
20
+ if (token && isAuthRoute) {
21
+ return stopChain(NextResponse.redirect(new URL("/", request.url)));
22
+ }
23
+ if (!token && !isPublicRoute && !isAuthRoute) {
24
+ const loginUrl = new URL("/login", request.url);
25
+ if (pathname !== "/") {
26
+ loginUrl.searchParams.set("redirect", pathname);
27
+ }
28
+ return stopChain(NextResponse.redirect(loginUrl));
29
+ }
30
+ return continueChain();
31
+ };
32
+ }
33
+
34
+ // src/middlewares/chain.ts
35
+ import { NextResponse as NextResponse2 } from "next/server";
36
+ function shouldProcessPath(pathname, config) {
37
+ const { excludePaths, includePaths } = config;
38
+ if (excludePaths?.length) {
39
+ const isExcluded = excludePaths.some(
40
+ (path) => pathname === path || pathname.startsWith(`${path}/`)
41
+ );
42
+ if (isExcluded) return false;
43
+ }
44
+ if (includePaths?.length) {
45
+ return includePaths.some((path) => pathname === path || pathname.startsWith(`${path}/`));
46
+ }
47
+ return true;
48
+ }
49
+ function createMiddlewareChain(middlewares) {
50
+ return async function chainedMiddleware(request) {
51
+ const { pathname } = request.nextUrl;
52
+ let currentRequest = request;
53
+ for (const middleware of middlewares) {
54
+ if (!shouldProcessPath(pathname, middleware)) {
55
+ continue;
56
+ }
57
+ const result = await middleware.handler(currentRequest);
58
+ if (result.type === "response") {
59
+ return result.response;
60
+ }
61
+ if (result.request) {
62
+ currentRequest = result.request;
63
+ }
64
+ }
65
+ return NextResponse2.next();
66
+ };
67
+ }
68
+
69
+ export {
70
+ continueChain,
71
+ stopChain,
72
+ createAuthMiddleware,
73
+ createMiddlewareChain
74
+ };
75
+ //# sourceMappingURL=chunk-47SDUOY2.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/middlewares/types.ts","../src/middlewares/create-auth-middleware.ts","../src/middlewares/chain.ts"],"sourcesContent":["import { NextRequest, NextResponse } from 'next/server';\r\n\r\nexport type MiddlewareResult =\r\n | { type: 'response'; response: NextResponse }\r\n | { type: 'next'; request?: NextRequest };\r\n\r\nexport type MiddlewareFunction = (\r\n request: NextRequest\r\n) => MiddlewareResult | Promise<MiddlewareResult>;\r\n\r\nexport interface MiddlewareConfig {\r\n name: string;\r\n handler: MiddlewareFunction;\r\n excludePaths?: string[];\r\n includePaths?: string[];\r\n}\r\n\r\nexport function continueChain(request?: NextRequest): MiddlewareResult {\r\n return { type: 'next', request };\r\n}\r\n\r\nexport function stopChain(response: NextResponse): MiddlewareResult {\r\n return { type: 'response', response };\r\n}\r\n","import { NextRequest, NextResponse } from 'next/server';\r\n\r\nimport { continueChain, MiddlewareConfig, MiddlewareFunction, MiddlewareResult, stopChain } from './types';\r\n\r\nfunction isRouteEquals(pathname: string, routes: string[]): boolean {\r\n return routes.some((route) => pathname === route || pathname.startsWith(`${route}/`));\r\n}\r\n\r\ninterface CreateAuthMiddlewareOptions {\r\n publicRoutes?: string[];\r\n authRoutes?: string[];\r\n}\r\n\r\nexport function createAuthMiddleware(options?: CreateAuthMiddlewareOptions): MiddlewareFunction {\r\n return (request: NextRequest) => {\r\n const { pathname } = request.nextUrl;\r\n const token = process.env.DUMMY_AUTH_TOKEN || request.cookies.get('greatapps')?.value;\r\n const isPublicRoute = isRouteEquals(pathname, options?.publicRoutes || []);\r\n const isAuthRoute = isRouteEquals(pathname, options?.authRoutes || []);\r\n\r\n if (token && isAuthRoute) {\r\n return stopChain(NextResponse.redirect(new URL('/', request.url)));\r\n }\r\n\r\n if (!token && !isPublicRoute && !isAuthRoute) {\r\n const loginUrl = new URL('/login', request.url);\r\n\r\n if (pathname !== '/') {\r\n loginUrl.searchParams.set('redirect', pathname);\r\n }\r\n\r\n return stopChain(NextResponse.redirect(loginUrl));\r\n }\r\n\r\n return continueChain();\r\n }\r\n}","import { NextRequest, NextResponse } from 'next/server';\r\n\r\nimport { MiddlewareConfig } from './types';\r\n\r\nfunction shouldProcessPath(pathname: string, config: MiddlewareConfig): boolean {\r\n const { excludePaths, includePaths } = config;\r\n\r\n if (excludePaths?.length) {\r\n const isExcluded = excludePaths.some(\r\n (path) => pathname === path || pathname.startsWith(`${path}/`)\r\n );\r\n if (isExcluded) return false;\r\n }\r\n\r\n if (includePaths?.length) {\r\n return includePaths.some((path) => pathname === path || pathname.startsWith(`${path}/`));\r\n }\r\n\r\n return true;\r\n}\r\n\r\nexport function createMiddlewareChain(middlewares: MiddlewareConfig[]) {\r\n return async function chainedMiddleware(request: NextRequest): Promise<NextResponse> {\r\n const { pathname } = request.nextUrl;\r\n let currentRequest = request;\r\n\r\n for (const middleware of middlewares) {\r\n if (!shouldProcessPath(pathname, middleware)) {\r\n continue;\r\n }\r\n\r\n const result = await middleware.handler(currentRequest);\r\n\r\n if (result.type === 'response') {\r\n return result.response;\r\n }\r\n\r\n if (result.request) {\r\n currentRequest = result.request;\r\n }\r\n }\r\n\r\n return NextResponse.next();\r\n };\r\n}\r\n"],"mappings":";AAiBO,SAAS,cAAc,SAAyC;AACrE,SAAO,EAAE,MAAM,QAAQ,QAAQ;AACjC;AAEO,SAAS,UAAU,UAA0C;AAClE,SAAO,EAAE,MAAM,YAAY,SAAS;AACtC;;;ACvBA,SAAsB,oBAAoB;AAI1C,SAAS,cAAc,UAAkB,QAA2B;AAClE,SAAO,OAAO,KAAK,CAAC,UAAU,aAAa,SAAS,SAAS,WAAW,GAAG,KAAK,GAAG,CAAC;AACtF;AAOO,SAAS,qBAAqB,SAA2D;AAC9F,SAAO,CAAC,YAAyB;AAC/B,UAAM,EAAE,SAAS,IAAI,QAAQ;AAC7B,UAAM,QAAQ,QAAQ,IAAI,oBAAoB,QAAQ,QAAQ,IAAI,WAAW,GAAG;AAChF,UAAM,gBAAgB,cAAc,UAAU,SAAS,gBAAgB,CAAC,CAAC;AACzE,UAAM,cAAc,cAAc,UAAU,SAAS,cAAc,CAAC,CAAC;AAErE,QAAI,SAAS,aAAa;AACxB,aAAO,UAAU,aAAa,SAAS,IAAI,IAAI,KAAK,QAAQ,GAAG,CAAC,CAAC;AAAA,IACnE;AAEA,QAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,aAAa;AAC5C,YAAM,WAAW,IAAI,IAAI,UAAU,QAAQ,GAAG;AAE9C,UAAI,aAAa,KAAK;AACpB,iBAAS,aAAa,IAAI,YAAY,QAAQ;AAAA,MAChD;AAEA,aAAO,UAAU,aAAa,SAAS,QAAQ,CAAC;AAAA,IAClD;AAEA,WAAO,cAAc;AAAA,EACvB;AACF;;;ACpCA,SAAsB,gBAAAA,qBAAoB;AAI1C,SAAS,kBAAkB,UAAkB,QAAmC;AAC9E,QAAM,EAAE,cAAc,aAAa,IAAI;AAEvC,MAAI,cAAc,QAAQ;AACxB,UAAM,aAAa,aAAa;AAAA,MAC9B,CAAC,SAAS,aAAa,QAAQ,SAAS,WAAW,GAAG,IAAI,GAAG;AAAA,IAC/D;AACA,QAAI,WAAY,QAAO;AAAA,EACzB;AAEA,MAAI,cAAc,QAAQ;AACxB,WAAO,aAAa,KAAK,CAAC,SAAS,aAAa,QAAQ,SAAS,WAAW,GAAG,IAAI,GAAG,CAAC;AAAA,EACzF;AAEA,SAAO;AACT;AAEO,SAAS,sBAAsB,aAAiC;AACrE,SAAO,eAAe,kBAAkB,SAA6C;AACnF,UAAM,EAAE,SAAS,IAAI,QAAQ;AAC7B,QAAI,iBAAiB;AAErB,eAAW,cAAc,aAAa;AACpC,UAAI,CAAC,kBAAkB,UAAU,UAAU,GAAG;AAC5C;AAAA,MACF;AAEA,YAAM,SAAS,MAAM,WAAW,QAAQ,cAAc;AAEtD,UAAI,OAAO,SAAS,YAAY;AAC9B,eAAO,OAAO;AAAA,MAChB;AAEA,UAAI,OAAO,SAAS;AAClB,yBAAiB,OAAO;AAAA,MAC1B;AAAA,IACF;AAEA,WAAOA,cAAa,KAAK;AAAA,EAC3B;AACF;","names":["NextResponse"]}
@@ -1,6 +1,3 @@
1
- import {
2
- safeServerAction
3
- } from "./chunk-JW4XRHLX.mjs";
4
1
  import {
5
2
  accountService,
6
3
  buildQueryParams,
@@ -9,6 +6,9 @@ import {
9
6
  import {
10
7
  api
11
8
  } from "./chunk-RV7ECGIH.mjs";
9
+ import {
10
+ safeServerAction
11
+ } from "./chunk-JW4XRHLX.mjs";
12
12
  import {
13
13
  ApiError
14
14
  } from "./chunk-UEWT6VFS.mjs";
@@ -280,4 +280,4 @@ export {
280
280
  addProjectUserAction,
281
281
  removeProjectUserAction
282
282
  };
283
- //# sourceMappingURL=chunk-ICUZDG2N.mjs.map
283
+ //# sourceMappingURL=chunk-4KASY4B6.mjs.map
@@ -304,4 +304,4 @@ export {
304
304
  authService,
305
305
  getClientInfoFromRequest
306
306
  };
307
- //# sourceMappingURL=chunk-7MBVHKTC.mjs.map
307
+ //# sourceMappingURL=chunk-5MR4OYS4.mjs.map
@@ -1,10 +1,10 @@
1
- import {
2
- safeServerAction
3
- } from "./chunk-JW4XRHLX.mjs";
4
1
  import {
5
2
  accountService,
6
3
  getUserContext
7
4
  } from "./chunk-Z3Q2LLBS.mjs";
5
+ import {
6
+ safeServerAction
7
+ } from "./chunk-JW4XRHLX.mjs";
8
8
  import {
9
9
  ApiError,
10
10
  findWhitelabel
@@ -162,4 +162,4 @@ export {
162
162
  confirmTwoFactorAction,
163
163
  disableTwoFactorAction
164
164
  };
165
- //# sourceMappingURL=chunk-QEFMNBSY.mjs.map
165
+ //# sourceMappingURL=chunk-5QQ2B7R6.mjs.map
package/dist/index.mjs CHANGED
@@ -1,3 +1,9 @@
1
+ import {
2
+ continueChain,
3
+ createAuthMiddleware,
4
+ createMiddlewareChain,
5
+ stopChain
6
+ } from "./chunk-47SDUOY2.mjs";
1
7
  import {
2
8
  SubscriptionItemSchema,
3
9
  SubscriptionSchema,
@@ -8,11 +14,11 @@ import {
8
14
  listProjectUsersAction,
9
15
  listSubscriptionsAction,
10
16
  removeProjectUserAction
11
- } from "./chunk-ICUZDG2N.mjs";
17
+ } from "./chunk-4KASY4B6.mjs";
12
18
  import {
13
19
  authService,
14
20
  getClientInfoFromRequest
15
- } from "./chunk-7MBVHKTC.mjs";
21
+ } from "./chunk-5MR4OYS4.mjs";
16
22
  import {
17
23
  changePasswordAction,
18
24
  confirmEmailChangeAction,
@@ -27,10 +33,7 @@ import {
27
33
  updateAccountAction,
28
34
  updateAccountUserByIdAction,
29
35
  updateUserAction
30
- } from "./chunk-QEFMNBSY.mjs";
31
- import {
32
- safeServerAction
33
- } from "./chunk-JW4XRHLX.mjs";
36
+ } from "./chunk-5QQ2B7R6.mjs";
34
37
  import {
35
38
  buildQueryParams,
36
39
  getUserContext
@@ -38,6 +41,9 @@ import {
38
41
  import {
39
42
  api
40
43
  } from "./chunk-RV7ECGIH.mjs";
44
+ import {
45
+ safeServerAction
46
+ } from "./chunk-JW4XRHLX.mjs";
41
47
  import {
42
48
  ApiError,
43
49
  PaginationParamsSchema,
@@ -54,32 +60,6 @@ var UserProfile = /* @__PURE__ */ ((UserProfile2) => {
54
60
  return UserProfile2;
55
61
  })(UserProfile || {});
56
62
 
57
- // src/providers/whitelabel.provider.tsx
58
- import { createContext, useContext } from "react";
59
- import { jsx } from "react/jsx-runtime";
60
- var WhitelabelContext = createContext(void 0);
61
- function WhitelabelProvider({
62
- children,
63
- whitelabel,
64
- whitelabelStyles = null
65
- }) {
66
- return /* @__PURE__ */ jsx(WhitelabelContext.Provider, { value: { whitelabel, whitelabelStyles }, children });
67
- }
68
- function useWhitelabel() {
69
- const context = useContext(WhitelabelContext);
70
- if (context === void 0) {
71
- throw new Error("useWhitelabel deve ser usado dentro de um WhitelabelProvider");
72
- }
73
- return context;
74
- }
75
- function useWhitelabelStyles() {
76
- const context = useContext(WhitelabelContext);
77
- if (context === void 0) {
78
- throw new Error("useWhitelabelStyles deve ser usado dentro de um WhitelabelProvider");
79
- }
80
- return context.whitelabelStyles;
81
- }
82
-
83
63
  // src/providers/query.provider.tsx
84
64
  import {
85
65
  QueryClient
@@ -91,7 +71,7 @@ import {
91
71
  } from "@tanstack/react-query-persist-client";
92
72
  import { broadcastQueryClient } from "@tanstack/query-broadcast-client-experimental";
93
73
  import { set, get, del } from "idb-keyval";
94
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
74
+ import { jsx, jsxs } from "react/jsx-runtime";
95
75
  var ReactQueryDevtools = process.env.NODE_ENV === "development" ? dynamic(
96
76
  () => import("./modern-4YXF5ES3.mjs").then((mod) => ({
97
77
  default: mod.ReactQueryDevtools
@@ -169,7 +149,7 @@ function QueryProvider({
169
149
  },
170
150
  children: [
171
151
  children,
172
- /* @__PURE__ */ jsx2(ReactQueryDevtools, { initialIsOpen: false })
152
+ /* @__PURE__ */ jsx(ReactQueryDevtools, { initialIsOpen: false })
173
153
  ]
174
154
  }
175
155
  );
@@ -177,9 +157,9 @@ function QueryProvider({
177
157
 
178
158
  // src/providers/auth.provider.tsx
179
159
  import {
180
- createContext as createContext2,
160
+ createContext,
181
161
  useCallback,
182
- useContext as useContext2,
162
+ useContext,
183
163
  useMemo
184
164
  } from "react";
185
165
  import { useQueryClient as useQueryClient3 } from "@tanstack/react-query";
@@ -206,7 +186,7 @@ async function fetchUser() {
206
186
  return result.success && result.data ? result.data : null;
207
187
  }
208
188
  async function validateUserSession() {
209
- const { validateSessionAction } = await import("./validate-session.action-K7RWN2GE.mjs");
189
+ const { validateSessionAction } = await import("./validate-session.action-QC2VBJ4N.mjs");
210
190
  return await validateSessionAction();
211
191
  }
212
192
  function useUserQuery() {
@@ -233,7 +213,7 @@ function useTwoFactorVerify() {
233
213
  const queryClient = useQueryClient();
234
214
  return useMutation({
235
215
  mutationFn: async ({ cookie, code }) => {
236
- const { verifyTwoFactorAction } = await import("./verify-two-factor.action-V6JQATK2.mjs");
216
+ const { verifyTwoFactorAction } = await import("./verify-two-factor.action-BAKUOXIH.mjs");
237
217
  return withAction(() => verifyTwoFactorAction(cookie, code))();
238
218
  },
239
219
  onSuccess: () => {
@@ -326,8 +306,8 @@ function useCurrentAccount() {
326
306
 
327
307
  // src/providers/auth.provider.tsx
328
308
  import { useRouter } from "next/navigation";
329
- import { jsx as jsx3 } from "react/jsx-runtime";
330
- var AuthContext = createContext2(
309
+ import { jsx as jsx2 } from "react/jsx-runtime";
310
+ var AuthContext = createContext(
331
311
  void 0
332
312
  );
333
313
  function AuthProvider({ children }) {
@@ -387,16 +367,42 @@ function AuthProvider({ children }) {
387
367
  }),
388
368
  [user, account, isAuthenticated, isLoading, login, register, logout]
389
369
  );
390
- return /* @__PURE__ */ jsx3(AuthContext.Provider, { value, children });
370
+ return /* @__PURE__ */ jsx2(AuthContext.Provider, { value, children });
391
371
  }
392
372
  function useAuth() {
393
- const context = useContext2(AuthContext);
373
+ const context = useContext(AuthContext);
394
374
  if (context === void 0) {
395
375
  throw new Error("useAuth deve ser usado dentro de um AuthProvider");
396
376
  }
397
377
  return context;
398
378
  }
399
379
 
380
+ // src/providers/whitelabel.provider.tsx
381
+ import { createContext as createContext2, useContext as useContext2 } from "react";
382
+ import { jsx as jsx3 } from "react/jsx-runtime";
383
+ var WhitelabelContext = createContext2(void 0);
384
+ function WhitelabelProvider({
385
+ children,
386
+ whitelabel,
387
+ whitelabelStyles = null
388
+ }) {
389
+ return /* @__PURE__ */ jsx3(WhitelabelContext.Provider, { value: { whitelabel, whitelabelStyles }, children });
390
+ }
391
+ function useWhitelabel() {
392
+ const context = useContext2(WhitelabelContext);
393
+ if (context === void 0) {
394
+ throw new Error("useWhitelabel deve ser usado dentro de um WhitelabelProvider");
395
+ }
396
+ return context;
397
+ }
398
+ function useWhitelabelStyles() {
399
+ const context = useContext2(WhitelabelContext);
400
+ if (context === void 0) {
401
+ throw new Error("useWhitelabelStyles deve ser usado dentro de um WhitelabelProvider");
402
+ }
403
+ return context.whitelabelStyles;
404
+ }
405
+
400
406
  // src/modules/projects/hooks/list-project-users.hook.ts
401
407
  import { useInfiniteQuery } from "@tanstack/react-query";
402
408
  var PAGE_SIZE = 20;
@@ -576,76 +582,6 @@ var ADDON_IDS = {
576
582
  AI: 6
577
583
  };
578
584
 
579
- // src/middlewares/create-auth-middleware.ts
580
- import { NextResponse } from "next/server";
581
-
582
- // src/middlewares/types.ts
583
- function continueChain(request) {
584
- return { type: "next", request };
585
- }
586
- function stopChain(response) {
587
- return { type: "response", response };
588
- }
589
-
590
- // src/middlewares/create-auth-middleware.ts
591
- function isRouteEquals(pathname, routes) {
592
- return routes.some((route) => pathname === route || pathname.startsWith(`${route}/`));
593
- }
594
- function createAuthMiddleware(options) {
595
- return (request) => {
596
- const { pathname } = request.nextUrl;
597
- const token = process.env.DUMMY_AUTH_TOKEN || request.cookies.get("greatapps")?.value;
598
- const isPublicRoute = isRouteEquals(pathname, options?.publicRoutes || []);
599
- const isAuthRoute = isRouteEquals(pathname, options?.authRoutes || []);
600
- if (token && isAuthRoute) {
601
- return stopChain(NextResponse.redirect(new URL("/", request.url)));
602
- }
603
- if (!token && !isPublicRoute && !isAuthRoute) {
604
- const loginUrl = new URL("/login", request.url);
605
- if (pathname !== "/") {
606
- loginUrl.searchParams.set("redirect", pathname);
607
- }
608
- return stopChain(NextResponse.redirect(loginUrl));
609
- }
610
- return continueChain();
611
- };
612
- }
613
-
614
- // src/middlewares/chain.ts
615
- import { NextResponse as NextResponse2 } from "next/server";
616
- function shouldProcessPath(pathname, config) {
617
- const { excludePaths, includePaths } = config;
618
- if (excludePaths?.length) {
619
- const isExcluded = excludePaths.some(
620
- (path) => pathname === path || pathname.startsWith(`${path}/`)
621
- );
622
- if (isExcluded) return false;
623
- }
624
- if (includePaths?.length) {
625
- return includePaths.some((path) => pathname === path || pathname.startsWith(`${path}/`));
626
- }
627
- return true;
628
- }
629
- function createMiddlewareChain(middlewares) {
630
- return async function chainedMiddleware(request) {
631
- const { pathname } = request.nextUrl;
632
- let currentRequest = request;
633
- for (const middleware of middlewares) {
634
- if (!shouldProcessPath(pathname, middleware)) {
635
- continue;
636
- }
637
- const result = await middleware.handler(currentRequest);
638
- if (result.type === "response") {
639
- return result.response;
640
- }
641
- if (result.request) {
642
- currentRequest = result.request;
643
- }
644
- }
645
- return NextResponse2.next();
646
- };
647
- }
648
-
649
585
  // src/infra/utils/clsx.ts
650
586
  import { clsx } from "clsx";
651
587
  import { twMerge } from "tailwind-merge";
@@ -7601,7 +7537,7 @@ function ChangePhoneModal({ open, onClose }) {
7601
7537
  return result.success;
7602
7538
  },
7603
7539
  resendFn: async () => {
7604
- const { requestPhoneChangeAction: requestPhoneChangeAction2 } = await import("./account-management.action-7QQCACDJ.mjs");
7540
+ const { requestPhoneChangeAction: requestPhoneChangeAction2 } = await import("./account-management.action-GPQUKGJ4.mjs");
7605
7541
  const result = await requestPhoneChangeAction2(phoneValue);
7606
7542
  if (!result.success) {
7607
7543
  throw new Error(result.error);
@@ -7814,7 +7750,7 @@ function ChangeEmailModal({ open, onClose }) {
7814
7750
  return result.success;
7815
7751
  },
7816
7752
  resendFn: async () => {
7817
- const { requestEmailChangeAction: requestEmailChangeAction2 } = await import("./account-management.action-7QQCACDJ.mjs");
7753
+ const { requestEmailChangeAction: requestEmailChangeAction2 } = await import("./account-management.action-GPQUKGJ4.mjs");
7818
7754
  const result = await requestEmailChangeAction2(emailToVerify);
7819
7755
  if (!result.success) {
7820
7756
  throw new Error(result.error);