@enfyra/sdk-nuxt 0.7.1 → 0.7.3
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/dist/module.cjs +4 -9
- package/dist/module.d.ts.map +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +4 -9
- package/dist/runtime/composables/useEnfyraAuth.js +1 -1
- package/dist/runtime/server/api/all.d.ts.map +1 -1
- package/dist/runtime/server/api/all.js +18 -1
- package/dist/runtime/server/api/auth/[provider].get.d.ts.map +1 -1
- package/dist/runtime/server/api/auth/[provider].get.js +17 -21
- package/package.json +1 -1
- package/src/module.ts +6 -11
- package/src/runtime/composables/useEnfyraAuth.ts +1 -1
- package/src/runtime/server/api/all.ts +21 -1
- package/src/runtime/server/api/auth/[provider].get.ts +21 -23
- package/dist/runtime/server/api/auth/[provider]/callback.get.d.ts +0 -3
- package/dist/runtime/server/api/auth/[provider]/callback.get.d.ts.map +0 -1
- package/dist/runtime/server/api/auth/[provider]/callback.get.js +0 -16
- package/src/runtime/server/api/auth/[provider]/callback.get.ts +0 -21
package/dist/module.cjs
CHANGED
|
@@ -99,18 +99,13 @@ declare module '#imports' {
|
|
|
99
99
|
method: "post"
|
|
100
100
|
});
|
|
101
101
|
kit.addServerHandler({
|
|
102
|
-
route: `${apiPrefix}/auth
|
|
103
|
-
handler: resolve("./runtime/server/api/auth/
|
|
104
|
-
method: "get"
|
|
105
|
-
});
|
|
106
|
-
kit.addServerHandler({
|
|
107
|
-
route: `${apiPrefix}/auth/:provider/callback`,
|
|
108
|
-
handler: resolve("./runtime/server/api/auth/[provider]/callback.get"),
|
|
102
|
+
route: `${apiPrefix}/auth/callback`,
|
|
103
|
+
handler: resolve("./runtime/server/api/auth/callback.get"),
|
|
109
104
|
method: "get"
|
|
110
105
|
});
|
|
111
106
|
kit.addServerHandler({
|
|
112
|
-
route: `${apiPrefix}/auth/
|
|
113
|
-
handler: resolve("./runtime/server/api/auth/
|
|
107
|
+
route: `${apiPrefix}/auth/[provider]`,
|
|
108
|
+
handler: resolve("./runtime/server/api/auth/[provider].get"),
|
|
114
109
|
method: "get"
|
|
115
110
|
});
|
|
116
111
|
kit.addServerHandler({
|
package/dist/module.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;;AAED,
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;;AAED,wBA2IG"}
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -96,18 +96,13 @@ declare module '#imports' {
|
|
|
96
96
|
method: "post"
|
|
97
97
|
});
|
|
98
98
|
addServerHandler({
|
|
99
|
-
route: `${apiPrefix}/auth
|
|
100
|
-
handler: resolve("./runtime/server/api/auth/
|
|
101
|
-
method: "get"
|
|
102
|
-
});
|
|
103
|
-
addServerHandler({
|
|
104
|
-
route: `${apiPrefix}/auth/:provider/callback`,
|
|
105
|
-
handler: resolve("./runtime/server/api/auth/[provider]/callback.get"),
|
|
99
|
+
route: `${apiPrefix}/auth/callback`,
|
|
100
|
+
handler: resolve("./runtime/server/api/auth/callback.get"),
|
|
106
101
|
method: "get"
|
|
107
102
|
});
|
|
108
103
|
addServerHandler({
|
|
109
|
-
route: `${apiPrefix}/auth/
|
|
110
|
-
handler: resolve("./runtime/server/api/auth/
|
|
104
|
+
route: `${apiPrefix}/auth/[provider]`,
|
|
105
|
+
handler: resolve("./runtime/server/api/auth/[provider].get"),
|
|
111
106
|
method: "get"
|
|
112
107
|
});
|
|
113
108
|
addServerHandler({
|
|
@@ -70,7 +70,7 @@ export function useEnfyraAuth() {
|
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
72
72
|
const currentUrl = window.location.href;
|
|
73
|
-
window.location.href =
|
|
73
|
+
window.location.href = `/api/auth/${provider}?redirect=${encodeURIComponent(currentUrl)}`;
|
|
74
74
|
};
|
|
75
75
|
return {
|
|
76
76
|
me,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"all.d.ts","sourceRoot":"","sources":["../../../../src/runtime/server/api/all.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"all.d.ts","sourceRoot":"","sources":["../../../../src/runtime/server/api/all.ts"],"names":[],"mappings":";AAaA,wBAyBG"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { defineEventHandler, setResponseHeaders } from "h3";
|
|
1
|
+
import { defineEventHandler, getQuery, sendRedirect, setResponseHeaders } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "#imports";
|
|
2
3
|
import { proxyToAPI } from "../../utils/server/proxy.js";
|
|
3
4
|
const CORS_HEADERS = {
|
|
4
5
|
"Access-Control-Allow-Origin": "*",
|
|
@@ -6,10 +7,26 @@ const CORS_HEADERS = {
|
|
|
6
7
|
"Access-Control-Allow-Headers": "Content-Type, Authorization",
|
|
7
8
|
"Access-Control-Max-Age": "86400"
|
|
8
9
|
};
|
|
10
|
+
const OAUTH_INIT_PATTERN = /\/auth\/(google|facebook|github)(?:\/|$|\?)/;
|
|
9
11
|
export default defineEventHandler(async (event) => {
|
|
10
12
|
setResponseHeaders(event, CORS_HEADERS);
|
|
11
13
|
if (event.method === "OPTIONS") {
|
|
12
14
|
return "";
|
|
13
15
|
}
|
|
16
|
+
const pathname = event.path?.split("?")[0] || event.path || "";
|
|
17
|
+
const oauthMatch = pathname.match(OAUTH_INIT_PATTERN);
|
|
18
|
+
if (event.method === "GET" && oauthMatch) {
|
|
19
|
+
const provider = oauthMatch[1];
|
|
20
|
+
const query = getQuery(event);
|
|
21
|
+
const redirectParam = query.redirect;
|
|
22
|
+
if (redirectParam) {
|
|
23
|
+
const config = useRuntimeConfig();
|
|
24
|
+
const apiUrl = config.public?.enfyraSDK?.apiUrl;
|
|
25
|
+
if (apiUrl) {
|
|
26
|
+
const backendUrl = `${apiUrl.replace(/\/+$/, "")}/auth/${provider}?redirect=${encodeURIComponent(redirectParam)}`;
|
|
27
|
+
return sendRedirect(event, backendUrl, 302);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
14
31
|
return proxyToAPI(event);
|
|
15
32
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"[provider].get.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/server/api/auth/[provider].get.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"[provider].get.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/server/api/auth/[provider].get.ts"],"names":[],"mappings":";AAcA,wBAqBG"}
|
|
@@ -1,31 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
|
+
createError,
|
|
2
3
|
defineEventHandler,
|
|
3
4
|
getQuery,
|
|
4
|
-
|
|
5
|
-
sendError,
|
|
5
|
+
getRouterParam,
|
|
6
6
|
sendRedirect
|
|
7
7
|
} from "h3";
|
|
8
8
|
import { useRuntimeConfig } from "#imports";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const provider = event.context.params?.provider;
|
|
15
|
-
if (!provider || !VALID_PROVIDERS.includes(provider)) {
|
|
16
|
-
return sendError(
|
|
17
|
-
event,
|
|
18
|
-
createError({
|
|
19
|
-
statusCode: 400,
|
|
20
|
-
statusMessage: `Invalid OAuth provider: ${provider}`
|
|
21
|
-
})
|
|
22
|
-
);
|
|
9
|
+
const OAUTH_PROVIDERS = ["google", "facebook", "github"];
|
|
10
|
+
export default defineEventHandler((event) => {
|
|
11
|
+
const provider = getRouterParam(event, "provider");
|
|
12
|
+
if (!provider || !OAUTH_PROVIDERS.includes(provider)) {
|
|
13
|
+
throw createError({ statusCode: 400, message: "Invalid OAuth provider" });
|
|
23
14
|
}
|
|
24
15
|
const query = getQuery(event);
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
const redirectParam = query.redirect;
|
|
17
|
+
if (!redirectParam) {
|
|
18
|
+
throw createError({ statusCode: 400, message: "Redirect URL is required" });
|
|
19
|
+
}
|
|
20
|
+
const config = useRuntimeConfig();
|
|
21
|
+
const apiUrl = config.public?.enfyraSDK?.apiUrl;
|
|
22
|
+
if (!apiUrl) {
|
|
23
|
+
throw createError({ statusCode: 500, message: "API URL not configured" });
|
|
29
24
|
}
|
|
30
|
-
|
|
25
|
+
const backendUrl = `${apiUrl.replace(/\/+$/, "")}/auth/${provider}?redirect=${encodeURIComponent(redirectParam)}`;
|
|
26
|
+
return sendRedirect(event, backendUrl, 302);
|
|
31
27
|
});
|
package/package.json
CHANGED
package/src/module.ts
CHANGED
|
@@ -130,22 +130,17 @@ declare module '#imports' {
|
|
|
130
130
|
method: "post",
|
|
131
131
|
});
|
|
132
132
|
|
|
133
|
-
// OAuth
|
|
133
|
+
// OAuth callback - sets cookies and redirects (must be before [provider])
|
|
134
134
|
addServerHandler({
|
|
135
|
-
route: `${apiPrefix}/auth
|
|
136
|
-
handler: resolve("./runtime/server/api/auth/
|
|
137
|
-
method: "get",
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
addServerHandler({
|
|
141
|
-
route: `${apiPrefix}/auth/:provider/callback`,
|
|
142
|
-
handler: resolve("./runtime/server/api/auth/[provider]/callback.get"),
|
|
135
|
+
route: `${apiPrefix}/auth/callback`,
|
|
136
|
+
handler: resolve("./runtime/server/api/auth/callback.get"),
|
|
143
137
|
method: "get",
|
|
144
138
|
});
|
|
145
139
|
|
|
140
|
+
// OAuth initiate - redirect to backend (not proxy)
|
|
146
141
|
addServerHandler({
|
|
147
|
-
route: `${apiPrefix}/auth/
|
|
148
|
-
handler: resolve("./runtime/server/api/auth/
|
|
142
|
+
route: `${apiPrefix}/auth/[provider]`,
|
|
143
|
+
handler: resolve("./runtime/server/api/auth/[provider].get"),
|
|
149
144
|
method: "get",
|
|
150
145
|
});
|
|
151
146
|
|
|
@@ -87,7 +87,7 @@ export function useEnfyraAuth(): UseEnfyraAuthReturn {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
const currentUrl = window.location.href;
|
|
90
|
-
window.location.href =
|
|
90
|
+
window.location.href = `/api/auth/${provider}?redirect=${encodeURIComponent(currentUrl)}`;
|
|
91
91
|
};
|
|
92
92
|
|
|
93
93
|
return {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { defineEventHandler, setResponseHeaders } from "h3";
|
|
1
|
+
import { defineEventHandler, getQuery, sendRedirect, setResponseHeaders } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "#imports";
|
|
2
3
|
import { proxyToAPI } from "../../utils/server/proxy";
|
|
3
4
|
|
|
4
5
|
const CORS_HEADERS = {
|
|
@@ -8,6 +9,8 @@ const CORS_HEADERS = {
|
|
|
8
9
|
'Access-Control-Max-Age': '86400',
|
|
9
10
|
};
|
|
10
11
|
|
|
12
|
+
const OAUTH_INIT_PATTERN = /\/auth\/(google|facebook|github)(?:\/|$|\?)/;
|
|
13
|
+
|
|
11
14
|
export default defineEventHandler(async (event) => {
|
|
12
15
|
setResponseHeaders(event, CORS_HEADERS);
|
|
13
16
|
|
|
@@ -15,5 +18,22 @@ export default defineEventHandler(async (event) => {
|
|
|
15
18
|
return '';
|
|
16
19
|
}
|
|
17
20
|
|
|
21
|
+
// OAuth initiate: redirect to backend, do NOT proxy
|
|
22
|
+
const pathname = event.path?.split('?')[0] || event.path || '';
|
|
23
|
+
const oauthMatch = pathname.match(OAUTH_INIT_PATTERN);
|
|
24
|
+
if (event.method === 'GET' && oauthMatch) {
|
|
25
|
+
const provider = oauthMatch[1];
|
|
26
|
+
const query = getQuery(event);
|
|
27
|
+
const redirectParam = query.redirect as string;
|
|
28
|
+
if (redirectParam) {
|
|
29
|
+
const config = useRuntimeConfig();
|
|
30
|
+
const apiUrl = config.public?.enfyraSDK?.apiUrl;
|
|
31
|
+
if (apiUrl) {
|
|
32
|
+
const backendUrl = `${apiUrl.replace(/\/+$/, "")}/auth/${provider}?redirect=${encodeURIComponent(redirectParam)}`;
|
|
33
|
+
return sendRedirect(event, backendUrl, 302);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
18
38
|
return proxyToAPI(event);
|
|
19
39
|
});
|
|
@@ -1,38 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth initiate - redirect browser to backend, do NOT proxy/fetch
|
|
3
|
+
*/
|
|
1
4
|
import {
|
|
5
|
+
createError,
|
|
2
6
|
defineEventHandler,
|
|
3
7
|
getQuery,
|
|
4
|
-
|
|
5
|
-
sendError,
|
|
8
|
+
getRouterParam,
|
|
6
9
|
sendRedirect,
|
|
7
10
|
} from "h3";
|
|
8
11
|
import { useRuntimeConfig } from "#imports";
|
|
9
|
-
import { normalizeUrl } from "../../../utils/url";
|
|
10
12
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
export default defineEventHandler(async (event) => {
|
|
14
|
-
const config = useRuntimeConfig();
|
|
15
|
-
const apiUrl = config.public.enfyraSDK?.apiUrl;
|
|
16
|
-
const provider = event.context.params?.provider;
|
|
13
|
+
const OAUTH_PROVIDERS = ["google", "facebook", "github"];
|
|
17
14
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
statusCode: 400,
|
|
23
|
-
statusMessage: `Invalid OAuth provider: ${provider}`,
|
|
24
|
-
})
|
|
25
|
-
);
|
|
15
|
+
export default defineEventHandler((event) => {
|
|
16
|
+
const provider = getRouterParam(event, "provider");
|
|
17
|
+
if (!provider || !OAUTH_PROVIDERS.includes(provider)) {
|
|
18
|
+
throw createError({ statusCode: 400, message: "Invalid OAuth provider" });
|
|
26
19
|
}
|
|
27
20
|
|
|
28
21
|
const query = getQuery(event);
|
|
29
|
-
const
|
|
22
|
+
const redirectParam = query.redirect as string;
|
|
23
|
+
if (!redirectParam) {
|
|
24
|
+
throw createError({ statusCode: 400, message: "Redirect URL is required" });
|
|
25
|
+
}
|
|
30
26
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
|
|
27
|
+
const config = useRuntimeConfig();
|
|
28
|
+
const apiUrl = config.public?.enfyraSDK?.apiUrl;
|
|
29
|
+
if (!apiUrl) {
|
|
30
|
+
throw createError({ statusCode: 500, message: "API URL not configured" });
|
|
35
31
|
}
|
|
36
32
|
|
|
37
|
-
|
|
33
|
+
const backendUrl = `${apiUrl.replace(/\/+$/, "")}/auth/${provider}?redirect=${encodeURIComponent(redirectParam)}`;
|
|
34
|
+
|
|
35
|
+
return sendRedirect(event, backendUrl, 302);
|
|
38
36
|
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"callback.get.d.ts","sourceRoot":"","sources":["../../../../../../src/runtime/server/api/auth/[provider]/callback.get.ts"],"names":[],"mappings":";AAQA,wBAYG"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
defineEventHandler,
|
|
3
|
-
getQuery,
|
|
4
|
-
sendRedirect
|
|
5
|
-
} from "h3";
|
|
6
|
-
import { useRuntimeConfig } from "#imports";
|
|
7
|
-
import { normalizeUrl } from "../../../../utils/url.js";
|
|
8
|
-
export default defineEventHandler(async (event) => {
|
|
9
|
-
const config = useRuntimeConfig();
|
|
10
|
-
const apiUrl = config.public.enfyraSDK?.apiUrl;
|
|
11
|
-
const provider = event.context.params?.provider;
|
|
12
|
-
const query = getQuery(event);
|
|
13
|
-
const queryString = new URLSearchParams(query).toString();
|
|
14
|
-
const backendUrl = normalizeUrl(apiUrl, `/auth/${provider}/callback?${queryString}`);
|
|
15
|
-
return sendRedirect(event, backendUrl, 302);
|
|
16
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
defineEventHandler,
|
|
3
|
-
getQuery,
|
|
4
|
-
sendRedirect,
|
|
5
|
-
} from "h3";
|
|
6
|
-
import { useRuntimeConfig } from "#imports";
|
|
7
|
-
import { normalizeUrl } from "../../../../utils/url";
|
|
8
|
-
|
|
9
|
-
export default defineEventHandler(async (event) => {
|
|
10
|
-
const config = useRuntimeConfig();
|
|
11
|
-
const apiUrl = config.public.enfyraSDK?.apiUrl;
|
|
12
|
-
const provider = event.context.params?.provider;
|
|
13
|
-
|
|
14
|
-
const query = getQuery(event);
|
|
15
|
-
const queryString = new URLSearchParams(query as Record<string, string>).toString();
|
|
16
|
-
|
|
17
|
-
// Redirect to backend OAuth callback
|
|
18
|
-
const backendUrl = normalizeUrl(apiUrl, `/auth/${provider}/callback?${queryString}`);
|
|
19
|
-
|
|
20
|
-
return sendRedirect(event, backendUrl, 302);
|
|
21
|
-
});
|