@enfyra/sdk-nuxt 0.3.16 → 0.3.17

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 (62) hide show
  1. package/index.ts +1 -1
  2. package/module.d.ts +2 -2
  3. package/{src/module.ts → module.ts} +10 -9
  4. package/package.json +22 -25
  5. package/src/composables/useEnfyraAuth.ts +1 -1
  6. package/dist/composables/useEnfyraApi.d.ts +0 -8
  7. package/dist/composables/useEnfyraApi.d.ts.map +0 -1
  8. package/dist/composables/useEnfyraApi.js +0 -363
  9. package/dist/composables/useEnfyraApi.mjs +0 -345
  10. package/dist/composables/useEnfyraAuth.d.ts +0 -89
  11. package/dist/composables/useEnfyraAuth.d.ts.map +0 -1
  12. package/dist/composables/useEnfyraAuth.js +0 -77
  13. package/dist/composables/useEnfyraAuth.mjs +0 -81
  14. package/dist/constants/auth.d.ts +0 -0
  15. package/dist/constants/auth.mjs +0 -3
  16. package/dist/constants/config.d.ts +0 -2
  17. package/dist/constants/config.d.ts.map +0 -1
  18. package/dist/constants/config.js +0 -1
  19. package/dist/constants/config.mjs +0 -1
  20. package/dist/module.cjs +0 -82
  21. package/dist/module.d.cts +0 -10
  22. package/dist/module.d.mts +0 -10
  23. package/dist/module.d.ts +0 -10
  24. package/dist/module.json +0 -9
  25. package/dist/module.mjs +0 -79
  26. package/dist/runtime/plugin/config-error.client.d.ts +0 -0
  27. package/dist/runtime/plugin/config-error.client.js +0 -107
  28. package/dist/runtime/plugin/config-error.client.mjs +0 -107
  29. package/dist/runtime/server/api/all.d.ts +0 -0
  30. package/dist/runtime/server/api/all.js +0 -5
  31. package/dist/runtime/server/api/all.mjs +0 -5
  32. package/dist/runtime/server/api/login.post.d.ts +0 -0
  33. package/dist/runtime/server/api/login.post.js +0 -62
  34. package/dist/runtime/server/api/login.post.mjs +0 -62
  35. package/dist/runtime/server/api/logout.post.d.ts +0 -0
  36. package/dist/runtime/server/api/logout.post.js +0 -35
  37. package/dist/runtime/server/api/logout.post.mjs +0 -35
  38. package/dist/runtime/server/middleware/auth.d.ts +0 -0
  39. package/dist/runtime/server/middleware/auth.js +0 -36
  40. package/dist/runtime/server/middleware/auth.mjs +0 -36
  41. package/dist/types/auth.d.ts +0 -43
  42. package/dist/types/auth.d.ts.map +0 -1
  43. package/dist/types/auth.js +0 -1
  44. package/dist/types/index.d.ts +0 -141
  45. package/dist/types/index.d.ts.map +0 -1
  46. package/dist/types/index.js +0 -1
  47. package/dist/types.d.mts +0 -7
  48. package/dist/types.d.ts +0 -7
  49. package/dist/utils/config.d.ts +0 -0
  50. package/dist/utils/config.mjs +0 -16
  51. package/dist/utils/http.d.ts +0 -8
  52. package/dist/utils/http.d.ts.map +0 -1
  53. package/dist/utils/http.js +0 -57
  54. package/dist/utils/http.mjs +0 -61
  55. package/dist/utils/server/proxy.d.ts +0 -0
  56. package/dist/utils/server/proxy.mjs +0 -14
  57. package/dist/utils/server/refreshToken.d.ts +0 -0
  58. package/dist/utils/server/refreshToken.mjs +0 -69
  59. package/dist/utils/url.d.ts +0 -12
  60. package/dist/utils/url.d.ts.map +0 -1
  61. package/dist/utils/url.js +0 -77
  62. package/dist/utils/url.mjs +0 -56
package/dist/module.d.cts DELETED
@@ -1,10 +0,0 @@
1
- import * as _nuxt_schema from '@nuxt/schema';
2
-
3
- interface ModuleOptions {
4
- apiUrl: string;
5
- apiPrefix?: string;
6
- }
7
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
8
-
9
- export { _default as default };
10
- export type { ModuleOptions };
package/dist/module.d.mts DELETED
@@ -1,10 +0,0 @@
1
- import * as _nuxt_schema from '@nuxt/schema';
2
-
3
- interface ModuleOptions {
4
- apiUrl: string;
5
- apiPrefix?: string;
6
- }
7
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
8
-
9
- export { _default as default };
10
- export type { ModuleOptions };
package/dist/module.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import * as _nuxt_schema from '@nuxt/schema';
2
-
3
- interface ModuleOptions {
4
- apiUrl: string;
5
- apiPrefix?: string;
6
- }
7
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
8
-
9
- export { _default as default };
10
- export type { ModuleOptions };
package/dist/module.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "name": "@enfyra/sdk-nuxt",
3
- "configKey": "enfyraSDK",
4
- "version": "0.3.16",
5
- "builder": {
6
- "@nuxt/module-builder": "0.8.4",
7
- "unbuild": "2.0.0"
8
- }
9
- }
package/dist/module.mjs DELETED
@@ -1,79 +0,0 @@
1
- import { defineNuxtModule, createResolver, addPlugin, addImportsDir, addServerHandler } from '@nuxt/kit';
2
- import { ENFYRA_API_PREFIX } from '../dist/constants/config.mjs';
3
-
4
- const module = defineNuxtModule({
5
- meta: {
6
- name: "@enfyra/sdk-nuxt",
7
- configKey: "enfyraSDK"
8
- },
9
- defaults: {
10
- apiUrl: "",
11
- apiPrefix: ENFYRA_API_PREFIX
12
- },
13
- setup(options, nuxt) {
14
- const normalizedOptions = {
15
- ...options,
16
- apiUrl: typeof options.apiUrl === "string" ? options.apiUrl.replace(/\/+$/, "") : options.apiUrl,
17
- apiPrefix: typeof options.apiPrefix === "string" ? options.apiPrefix.trim() ? "/" + options.apiPrefix.replace(/^\/+|\/+$/g, "").replace(/\/+/g, "/") : ENFYRA_API_PREFIX : ENFYRA_API_PREFIX
18
- };
19
- const apiPrefix = normalizedOptions.apiPrefix;
20
- const { resolve } = createResolver(import.meta.url);
21
- if (!normalizedOptions.apiUrl) {
22
- console.warn(
23
- `[Enfyra SDK Nuxt] Missing required configuration:
24
- - apiUrl is required
25
- Please configure it in your nuxt.config.ts:
26
- enfyraSDK: {
27
- apiUrl: 'https://your-api-url'
28
- }`
29
- );
30
- nuxt.options.runtimeConfig.public.enfyraSDK = {
31
- ...normalizedOptions,
32
- apiPrefix,
33
- configError: true,
34
- configErrorMessage: "Enfyra SDK: apiUrl is required. Please configure it in nuxt.config.ts"
35
- };
36
- } else {
37
- nuxt.options.runtimeConfig.public.enfyraSDK = {
38
- ...normalizedOptions,
39
- apiPrefix
40
- };
41
- }
42
- if (!normalizedOptions.apiUrl) {
43
- addPlugin({
44
- src: resolve("./runtime/plugin/config-error.client"),
45
- mode: "client"
46
- });
47
- }
48
- addImportsDir(resolve("./composables"));
49
- nuxt.hook("prepare:types", ({ declarations, references }) => {
50
- references.push({
51
- path: resolve("./types/nuxt-imports.d.ts")
52
- });
53
- });
54
- addServerHandler({
55
- handler: resolve("./runtime/server/middleware/auth"),
56
- middleware: true
57
- });
58
- addServerHandler({
59
- route: `${apiPrefix}/login`,
60
- handler: resolve("./runtime/server/api/login.post"),
61
- method: "post"
62
- });
63
- addServerHandler({
64
- route: `${apiPrefix}/logout`,
65
- handler: resolve("./runtime/server/api/logout.post"),
66
- method: "post"
67
- });
68
- addServerHandler({
69
- route: "/assets/**",
70
- handler: resolve("./runtime/server/api/all")
71
- });
72
- addServerHandler({
73
- route: `${apiPrefix}/**`,
74
- handler: resolve("./runtime/server/api/all")
75
- });
76
- }
77
- });
78
-
79
- export { module as default };
File without changes
@@ -1,107 +0,0 @@
1
- import { defineNuxtPlugin, useRuntimeConfig } from "#imports";
2
- export default defineNuxtPlugin(() => {
3
- const config = useRuntimeConfig().public?.enfyraSDK;
4
- if (config?.configError) {
5
- if (typeof window !== "undefined" && document) {
6
- let showError = function() {
7
- const errorDiv = document.createElement("div");
8
- errorDiv.id = "enfyra-config-error";
9
- errorDiv.style.cssText = `
10
- position: fixed;
11
- top: 0;
12
- left: 0;
13
- right: 0;
14
- bottom: 0;
15
- background: rgba(0, 0, 0, 0.9);
16
- display: flex;
17
- align-items: center;
18
- justify-content: center;
19
- z-index: 999999;
20
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
21
- `;
22
- const content = document.createElement("div");
23
- content.style.cssText = `
24
- background: white;
25
- padding: 40px;
26
- border-radius: 12px;
27
- max-width: 600px;
28
- width: 90%;
29
- box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
30
- `;
31
- content.innerHTML = `
32
- <div style="display: flex; align-items: center; margin-bottom: 20px;">
33
- <svg width="32" height="32" viewBox="0 0 24 24" fill="none" style="margin-right: 12px;">
34
- <circle cx="12" cy="12" r="10" stroke="#ef4444" stroke-width="2"/>
35
- <path d="M12 8v4M12 16h.01" stroke="#ef4444" stroke-width="2" stroke-linecap="round"/>
36
- </svg>
37
- <h1 style="margin: 0; color: #1f2937; font-size: 24px; font-weight: 600;">
38
- Configuration Error
39
- </h1>
40
- </div>
41
-
42
- <div style="color: #4b5563; margin-bottom: 24px; line-height: 1.6;">
43
- <p style="margin: 0 0 16px 0; font-size: 16px;">
44
- <strong>Enfyra SDK</strong> is not configured properly.
45
- </p>
46
- <p style="margin: 0; color: #6b7280; font-size: 14px;">
47
- ${config?.configErrorMessage || "Missing required configuration"}
48
- </p>
49
- </div>
50
-
51
- <div style="background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 8px; padding: 16px; margin-bottom: 24px;">
52
- <p style="margin: 0 0 12px 0; color: #6b7280; font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px;">
53
- Add to your nuxt.config.ts:
54
- </p>
55
- <pre style="margin: 0; background: #1f2937; color: #f3f4f6; padding: 16px; border-radius: 6px; overflow-x: auto; font-size: 14px; line-height: 1.4;"><code>export default defineNuxtConfig({
56
- modules: ["@enfyra/sdk-nuxt"],
57
- enfyraSDK: {
58
- <span style="color: #fbbf24;">apiUrl</span>: <span style="color: #34d399;">"https://your-api-url"</span>
59
- }
60
- })</code></pre>
61
- </div>
62
-
63
- <div style="display: flex; gap: 12px;">
64
- <button onclick="location.reload()" style="
65
- background: #3b82f6;
66
- color: white;
67
- border: none;
68
- padding: 10px 20px;
69
- border-radius: 6px;
70
- font-size: 14px;
71
- font-weight: 500;
72
- cursor: pointer;
73
- transition: background 0.2s;
74
- " onmouseover="this.style.background='#2563eb'" onmouseout="this.style.background='#3b82f6'">
75
- Reload Page
76
- </button>
77
- <button onclick="document.getElementById('enfyra-config-error').style.display='none'" style="
78
- background: #f3f4f6;
79
- color: #4b5563;
80
- border: 1px solid #e5e7eb;
81
- padding: 10px 20px;
82
- border-radius: 6px;
83
- font-size: 14px;
84
- font-weight: 500;
85
- cursor: pointer;
86
- transition: all 0.2s;
87
- " onmouseover="this.style.background='#e5e7eb'" onmouseout="this.style.background='#f3f4f6'">
88
- Dismiss
89
- </button>
90
- </div>
91
- `;
92
- errorDiv.appendChild(content);
93
- document.body.appendChild(errorDiv);
94
- console.error(
95
- "%c\u26A0\uFE0F Enfyra SDK Configuration Error",
96
- "color: #ef4444; font-size: 16px; font-weight: bold;",
97
- "\n\n" + (config?.configErrorMessage || "Missing required configuration") + '\n\nPlease add the following to your nuxt.config.ts:\n\nenfyraSDK: {\n apiUrl: "https://your-api-url"\n}'
98
- );
99
- };
100
- if (document.readyState === "loading") {
101
- document.addEventListener("DOMContentLoaded", showError);
102
- } else {
103
- showError();
104
- }
105
- }
106
- }
107
- });
@@ -1,107 +0,0 @@
1
- import { defineNuxtPlugin, useRuntimeConfig } from "#imports";
2
- export default defineNuxtPlugin(() => {
3
- const config = useRuntimeConfig().public?.enfyraSDK;
4
- if (config?.configError) {
5
- if (typeof window !== "undefined" && document) {
6
- let showError = function() {
7
- const errorDiv = document.createElement("div");
8
- errorDiv.id = "enfyra-config-error";
9
- errorDiv.style.cssText = `
10
- position: fixed;
11
- top: 0;
12
- left: 0;
13
- right: 0;
14
- bottom: 0;
15
- background: rgba(0, 0, 0, 0.9);
16
- display: flex;
17
- align-items: center;
18
- justify-content: center;
19
- z-index: 999999;
20
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
21
- `;
22
- const content = document.createElement("div");
23
- content.style.cssText = `
24
- background: white;
25
- padding: 40px;
26
- border-radius: 12px;
27
- max-width: 600px;
28
- width: 90%;
29
- box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
30
- `;
31
- content.innerHTML = `
32
- <div style="display: flex; align-items: center; margin-bottom: 20px;">
33
- <svg width="32" height="32" viewBox="0 0 24 24" fill="none" style="margin-right: 12px;">
34
- <circle cx="12" cy="12" r="10" stroke="#ef4444" stroke-width="2"/>
35
- <path d="M12 8v4M12 16h.01" stroke="#ef4444" stroke-width="2" stroke-linecap="round"/>
36
- </svg>
37
- <h1 style="margin: 0; color: #1f2937; font-size: 24px; font-weight: 600;">
38
- Configuration Error
39
- </h1>
40
- </div>
41
-
42
- <div style="color: #4b5563; margin-bottom: 24px; line-height: 1.6;">
43
- <p style="margin: 0 0 16px 0; font-size: 16px;">
44
- <strong>Enfyra SDK</strong> is not configured properly.
45
- </p>
46
- <p style="margin: 0; color: #6b7280; font-size: 14px;">
47
- ${config?.configErrorMessage || "Missing required configuration"}
48
- </p>
49
- </div>
50
-
51
- <div style="background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 8px; padding: 16px; margin-bottom: 24px;">
52
- <p style="margin: 0 0 12px 0; color: #6b7280; font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px;">
53
- Add to your nuxt.config.ts:
54
- </p>
55
- <pre style="margin: 0; background: #1f2937; color: #f3f4f6; padding: 16px; border-radius: 6px; overflow-x: auto; font-size: 14px; line-height: 1.4;"><code>export default defineNuxtConfig({
56
- modules: ["@enfyra/sdk-nuxt"],
57
- enfyraSDK: {
58
- <span style="color: #fbbf24;">apiUrl</span>: <span style="color: #34d399;">"https://your-api-url"</span>
59
- }
60
- })</code></pre>
61
- </div>
62
-
63
- <div style="display: flex; gap: 12px;">
64
- <button onclick="location.reload()" style="
65
- background: #3b82f6;
66
- color: white;
67
- border: none;
68
- padding: 10px 20px;
69
- border-radius: 6px;
70
- font-size: 14px;
71
- font-weight: 500;
72
- cursor: pointer;
73
- transition: background 0.2s;
74
- " onmouseover="this.style.background='#2563eb'" onmouseout="this.style.background='#3b82f6'">
75
- Reload Page
76
- </button>
77
- <button onclick="document.getElementById('enfyra-config-error').style.display='none'" style="
78
- background: #f3f4f6;
79
- color: #4b5563;
80
- border: 1px solid #e5e7eb;
81
- padding: 10px 20px;
82
- border-radius: 6px;
83
- font-size: 14px;
84
- font-weight: 500;
85
- cursor: pointer;
86
- transition: all 0.2s;
87
- " onmouseover="this.style.background='#e5e7eb'" onmouseout="this.style.background='#f3f4f6'">
88
- Dismiss
89
- </button>
90
- </div>
91
- `;
92
- errorDiv.appendChild(content);
93
- document.body.appendChild(errorDiv);
94
- console.error(
95
- "%c\u26A0\uFE0F Enfyra SDK Configuration Error",
96
- "color: #ef4444; font-size: 16px; font-weight: bold;",
97
- "\n\n" + (config?.configErrorMessage || "Missing required configuration") + '\n\nPlease add the following to your nuxt.config.ts:\n\nenfyraSDK: {\n apiUrl: "https://your-api-url"\n}'
98
- );
99
- };
100
- if (document.readyState === "loading") {
101
- document.addEventListener("DOMContentLoaded", showError);
102
- } else {
103
- showError();
104
- }
105
- }
106
- }
107
- });
File without changes
@@ -1,5 +0,0 @@
1
- import { defineEventHandler } from "h3";
2
- import { proxyToAPI } from "../../../utils/server/proxy";
3
- export default defineEventHandler(async (event) => {
4
- return proxyToAPI(event);
5
- });
@@ -1,5 +0,0 @@
1
- import { defineEventHandler } from "h3";
2
- import { proxyToAPI } from "../../../utils/server/proxy";
3
- export default defineEventHandler(async (event) => {
4
- return proxyToAPI(event);
5
- });
File without changes
@@ -1,62 +0,0 @@
1
- import {
2
- defineEventHandler,
3
- readBody,
4
- setCookie,
5
- createError,
6
- sendError,
7
- getHeader
8
- } from "h3";
9
- import { useRuntimeConfig } from "#imports";
10
- import { $fetch } from "ofetch";
11
- import {
12
- ACCESS_TOKEN_KEY,
13
- REFRESH_TOKEN_KEY,
14
- EXP_TIME_KEY
15
- } from "../../../constants/auth";
16
- import { normalizeUrl } from "../../../utils/url";
17
- export default defineEventHandler(async (event) => {
18
- const config = useRuntimeConfig();
19
- const apiUrl = config.public.enfyraSDK?.apiUrl;
20
- try {
21
- const body = await readBody(event);
22
- const response = await $fetch(normalizeUrl(apiUrl, "/auth/login"), {
23
- method: "POST",
24
- body,
25
- headers: {
26
- cookie: getHeader(event, "cookie") || ""
27
- }
28
- });
29
- const { accessToken, refreshToken, expTime } = response;
30
- const cookieOptions = {
31
- httpOnly: true,
32
- secure: true,
33
- sameSite: "lax",
34
- path: "/"
35
- };
36
- setCookie(event, ACCESS_TOKEN_KEY, accessToken, cookieOptions);
37
- setCookie(event, REFRESH_TOKEN_KEY, refreshToken, cookieOptions);
38
- setCookie(event, EXP_TIME_KEY, String(expTime), cookieOptions);
39
- return { accessToken };
40
- } catch (err) {
41
- const statusCode = err?.response?.status || err?.statusCode || 401;
42
- const errorData = err?.response?._data || err?.data;
43
- let errorMessage = "Authentication failed";
44
- let errorCode = "AUTHENTICATION_ERROR";
45
- if (errorData?.error) {
46
- errorMessage = errorData.error.message || errorData.message || errorMessage;
47
- errorCode = errorData.error.code || errorCode;
48
- }
49
- return sendError(
50
- event,
51
- createError({
52
- statusCode,
53
- statusMessage: errorMessage,
54
- data: {
55
- code: errorCode,
56
- details: errorData?.error?.details,
57
- correlationId: errorData?.error?.correlationId
58
- }
59
- })
60
- );
61
- }
62
- });
@@ -1,62 +0,0 @@
1
- import {
2
- defineEventHandler,
3
- readBody,
4
- setCookie,
5
- createError,
6
- sendError,
7
- getHeader
8
- } from "h3";
9
- import { useRuntimeConfig } from "#imports";
10
- import { $fetch } from "ofetch";
11
- import {
12
- ACCESS_TOKEN_KEY,
13
- REFRESH_TOKEN_KEY,
14
- EXP_TIME_KEY
15
- } from "../../../constants/auth";
16
- import { normalizeUrl } from "../../../utils/url";
17
- export default defineEventHandler(async (event) => {
18
- const config = useRuntimeConfig();
19
- const apiUrl = config.public.enfyraSDK?.apiUrl;
20
- try {
21
- const body = await readBody(event);
22
- const response = await $fetch(normalizeUrl(apiUrl, "/auth/login"), {
23
- method: "POST",
24
- body,
25
- headers: {
26
- cookie: getHeader(event, "cookie") || ""
27
- }
28
- });
29
- const { accessToken, refreshToken, expTime } = response;
30
- const cookieOptions = {
31
- httpOnly: true,
32
- secure: true,
33
- sameSite: "lax",
34
- path: "/"
35
- };
36
- setCookie(event, ACCESS_TOKEN_KEY, accessToken, cookieOptions);
37
- setCookie(event, REFRESH_TOKEN_KEY, refreshToken, cookieOptions);
38
- setCookie(event, EXP_TIME_KEY, String(expTime), cookieOptions);
39
- return { accessToken };
40
- } catch (err) {
41
- const statusCode = err?.response?.status || err?.statusCode || 401;
42
- const errorData = err?.response?._data || err?.data;
43
- let errorMessage = "Authentication failed";
44
- let errorCode = "AUTHENTICATION_ERROR";
45
- if (errorData?.error) {
46
- errorMessage = errorData.error.message || errorData.message || errorMessage;
47
- errorCode = errorData.error.code || errorCode;
48
- }
49
- return sendError(
50
- event,
51
- createError({
52
- statusCode,
53
- statusMessage: errorMessage,
54
- data: {
55
- code: errorCode,
56
- details: errorData?.error?.details,
57
- correlationId: errorData?.error?.correlationId
58
- }
59
- })
60
- );
61
- }
62
- });
File without changes
@@ -1,35 +0,0 @@
1
- import { defineEventHandler, getHeader, getCookie, deleteCookie } from "h3";
2
- import { useRuntimeConfig } from "#imports";
3
- import { $fetch } from "ofetch";
4
- import {
5
- ACCESS_TOKEN_KEY,
6
- REFRESH_TOKEN_KEY,
7
- EXP_TIME_KEY
8
- } from "../../../constants/auth";
9
- import { normalizeUrl } from "../../../utils/url";
10
- export default defineEventHandler(async (event) => {
11
- const config = useRuntimeConfig();
12
- const apiUrl = config.public?.enfyraSDK?.apiUrl;
13
- const refreshToken = getCookie(event, REFRESH_TOKEN_KEY);
14
- try {
15
- const result = await $fetch(normalizeUrl(apiUrl, "/auth/logout"), {
16
- method: "POST",
17
- headers: {
18
- cookie: getHeader(event, "cookie") || "",
19
- authorization: event.context.proxyHeaders?.authorization
20
- },
21
- body: {
22
- refreshToken
23
- }
24
- });
25
- deleteCookie(event, ACCESS_TOKEN_KEY);
26
- deleteCookie(event, REFRESH_TOKEN_KEY);
27
- deleteCookie(event, EXP_TIME_KEY);
28
- return result;
29
- } catch (err) {
30
- deleteCookie(event, ACCESS_TOKEN_KEY);
31
- deleteCookie(event, REFRESH_TOKEN_KEY);
32
- deleteCookie(event, EXP_TIME_KEY);
33
- return { success: false, message: "Logout completed locally" };
34
- }
35
- });
@@ -1,35 +0,0 @@
1
- import { defineEventHandler, getHeader, getCookie, deleteCookie } from "h3";
2
- import { useRuntimeConfig } from "#imports";
3
- import { $fetch } from "ofetch";
4
- import {
5
- ACCESS_TOKEN_KEY,
6
- REFRESH_TOKEN_KEY,
7
- EXP_TIME_KEY
8
- } from "../../../constants/auth";
9
- import { normalizeUrl } from "../../../utils/url";
10
- export default defineEventHandler(async (event) => {
11
- const config = useRuntimeConfig();
12
- const apiUrl = config.public?.enfyraSDK?.apiUrl;
13
- const refreshToken = getCookie(event, REFRESH_TOKEN_KEY);
14
- try {
15
- const result = await $fetch(normalizeUrl(apiUrl, "/auth/logout"), {
16
- method: "POST",
17
- headers: {
18
- cookie: getHeader(event, "cookie") || "",
19
- authorization: event.context.proxyHeaders?.authorization
20
- },
21
- body: {
22
- refreshToken
23
- }
24
- });
25
- deleteCookie(event, ACCESS_TOKEN_KEY);
26
- deleteCookie(event, REFRESH_TOKEN_KEY);
27
- deleteCookie(event, EXP_TIME_KEY);
28
- return result;
29
- } catch (err) {
30
- deleteCookie(event, ACCESS_TOKEN_KEY);
31
- deleteCookie(event, REFRESH_TOKEN_KEY);
32
- deleteCookie(event, EXP_TIME_KEY);
33
- return { success: false, message: "Logout completed locally" };
34
- }
35
- });
File without changes
@@ -1,36 +0,0 @@
1
- import { defineEventHandler, getCookie } from "h3";
2
- import { useRuntimeConfig } from "#imports";
3
- import {
4
- validateTokens,
5
- refreshAccessToken
6
- } from "../../../utils/server/refreshToken";
7
- import { REFRESH_TOKEN_KEY } from "../../../constants/auth";
8
- export default defineEventHandler(async (event) => {
9
- if (event.node.req.url === "/api/login" || event.node.req.url === "/api/logout") {
10
- return;
11
- }
12
- const { accessToken, needsRefresh } = validateTokens(event);
13
- let currentAccessToken = accessToken;
14
- if (needsRefresh) {
15
- const refreshToken = getCookie(event, REFRESH_TOKEN_KEY);
16
- if (refreshToken) {
17
- try {
18
- const config = useRuntimeConfig();
19
- const apiUrl = config.public?.enfyraSDK?.apiUrl;
20
- if (apiUrl) {
21
- currentAccessToken = await refreshAccessToken(
22
- event,
23
- refreshToken,
24
- apiUrl
25
- );
26
- }
27
- } catch (error) {
28
- currentAccessToken = null;
29
- }
30
- }
31
- }
32
- if (currentAccessToken) {
33
- event.context.proxyHeaders = event.context.proxyHeaders || {};
34
- event.context.proxyHeaders.authorization = `Bearer ${currentAccessToken}`;
35
- }
36
- });
@@ -1,36 +0,0 @@
1
- import { defineEventHandler, getCookie } from "h3";
2
- import { useRuntimeConfig } from "#imports";
3
- import {
4
- validateTokens,
5
- refreshAccessToken
6
- } from "../../../utils/server/refreshToken";
7
- import { REFRESH_TOKEN_KEY } from "../../../constants/auth";
8
- export default defineEventHandler(async (event) => {
9
- if (event.node.req.url === "/api/login" || event.node.req.url === "/api/logout") {
10
- return;
11
- }
12
- const { accessToken, needsRefresh } = validateTokens(event);
13
- let currentAccessToken = accessToken;
14
- if (needsRefresh) {
15
- const refreshToken = getCookie(event, REFRESH_TOKEN_KEY);
16
- if (refreshToken) {
17
- try {
18
- const config = useRuntimeConfig();
19
- const apiUrl = config.public?.enfyraSDK?.apiUrl;
20
- if (apiUrl) {
21
- currentAccessToken = await refreshAccessToken(
22
- event,
23
- refreshToken,
24
- apiUrl
25
- );
26
- }
27
- } catch (error) {
28
- currentAccessToken = null;
29
- }
30
- }
31
- }
32
- if (currentAccessToken) {
33
- event.context.proxyHeaders = event.context.proxyHeaders || {};
34
- event.context.proxyHeaders.authorization = `Bearer ${currentAccessToken}`;
35
- }
36
- });