@meistrari/auth-nuxt 3.7.0 → 3.8.1

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/README.md CHANGED
@@ -12,9 +12,30 @@ This SDK supports two authentication models:
12
12
  ## Installation
13
13
 
14
14
  ```bash
15
- npm install @meistrari/auth-nuxt
15
+ bun add @meistrari/auth-nuxt
16
16
  ```
17
17
 
18
+ ## Quick Start
19
+
20
+ ```ts
21
+ export default defineNuxtConfig({
22
+ modules: ['@meistrari/auth-nuxt'],
23
+ telaAuth: {
24
+ apiUrl: 'https://auth.tela.com',
25
+ application: {
26
+ enabled: true,
27
+ dashboardUrl: 'https://accounts.tela.com',
28
+ applicationId: 'app_123',
29
+ redirectUri: 'https://your-app.com/auth/callback',
30
+ },
31
+ },
32
+ })
33
+ ```
34
+
35
+ Application auth auto-imports `useTelaApplicationAuth()`, registers `<TelaRole>`, installs role directives, and adds SDK routes under `/auth/*` plus `/api/auth/api-key/**`. `useTelaApiKey()` is also available; in application mode it targets the local API key proxy for app-scoped user API keys.
36
+
37
+ First-party auth auto-imports `useTelaSession()`, `useTelaOrganization()`, and `useTelaApiKey()`.
38
+
18
39
  ## API Reference
19
40
 
20
41
  See it on [Pantry](https://pantry.tela.tools/ingredients/auth-nuxt/api)
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@meistrari/auth-nuxt",
3
3
  "configKey": "telaAuth",
4
- "version": "3.7.0",
4
+ "version": "3.0.1",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -12,6 +12,11 @@ const module$1 = defineNuxtModule({
12
12
  setup(options, nuxt) {
13
13
  const resolver = createResolver(import.meta.url);
14
14
  nuxt.options.runtimeConfig.public.telaAuth = options;
15
+ addImports({
16
+ name: "useTelaApiKey",
17
+ as: "useTelaApiKey",
18
+ from: resolver.resolve("runtime/composables/api-key")
19
+ });
15
20
  if (options.application?.enabled) {
16
21
  addImports({
17
22
  name: "useTelaApplicationAuth",
@@ -71,6 +76,10 @@ const module$1 = defineNuxtModule({
71
76
  handler: resolver.resolve("./runtime/server/routes/auth/whoami"),
72
77
  method: "get"
73
78
  });
79
+ addServerHandler({
80
+ route: "/api/auth/api-key/**",
81
+ handler: resolver.resolve("./runtime/server/routes/auth/api-key-proxy")
82
+ });
74
83
  addPlugin(resolver.resolve("./runtime/plugins/application-token-refresh"));
75
84
  addPlugin(resolver.resolve("./runtime/plugins/auth-guard"));
76
85
  addPlugin(resolver.resolve("./runtime/plugins/directives"));
@@ -92,11 +101,6 @@ const module$1 = defineNuxtModule({
92
101
  as: "useTelaOrganization",
93
102
  from: resolver.resolve("runtime/composables/organization")
94
103
  });
95
- addImports({
96
- name: "useTelaApiKey",
97
- as: "useTelaApiKey",
98
- from: resolver.resolve("runtime/composables/api-key")
99
- });
100
104
  addPlugin(resolver.resolve("./runtime/plugins/handshake"));
101
105
  }
102
106
  });
@@ -1,9 +1,13 @@
1
- import { useCookie, useRuntimeConfig } from "#app";
1
+ import { useCookie, useRequestURL, useRuntimeConfig } from "#app";
2
2
  import { createNuxtAuthClient } from "../shared.js";
3
3
  export function useTelaApiKey() {
4
- const { jwtCookieName, apiUrl } = useRuntimeConfig().public.telaAuth;
4
+ const { application, jwtCookieName, apiUrl } = useRuntimeConfig().public.telaAuth;
5
5
  const tokenCookie = useCookie(jwtCookieName);
6
- const authClient = createNuxtAuthClient(apiUrl, () => tokenCookie.value ?? null);
6
+ const requestUrl = useRequestURL();
7
+ const authClient = createNuxtAuthClient(
8
+ application?.enabled ? requestUrl.origin : apiUrl,
9
+ () => application?.enabled ? null : tokenCookie.value ?? null
10
+ );
7
11
  async function createApiKey(payload) {
8
12
  return await authClient.apiKey.createApiKey(payload);
9
13
  }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<string>>;
2
+ export default _default;
@@ -0,0 +1,58 @@
1
+ import { createError, useRuntimeConfig } from "#imports";
2
+ import {
3
+ defineEventHandler,
4
+ getCookie,
5
+ getHeaders,
6
+ getRequestURL,
7
+ readRawBody,
8
+ setResponseHeader,
9
+ setResponseStatus
10
+ } from "h3";
11
+ const ALLOWED_REQUEST_HEADERS = /* @__PURE__ */ new Set([
12
+ "accept",
13
+ "content-type"
14
+ ]);
15
+ const ALLOWED_RESPONSE_HEADERS = /* @__PURE__ */ new Set([
16
+ "cache-control",
17
+ "content-type"
18
+ ]);
19
+ export default defineEventHandler(async (event) => {
20
+ const authConfig = useRuntimeConfig(event).public.telaAuth;
21
+ const accessToken = getCookie(event, "tela-access-token");
22
+ if (!authConfig.application?.enabled) {
23
+ throw createError({
24
+ statusCode: 404,
25
+ statusMessage: "Not Found"
26
+ });
27
+ }
28
+ if (!accessToken) {
29
+ throw createError({
30
+ statusCode: 401,
31
+ statusMessage: "Unauthorized",
32
+ message: "No access token found"
33
+ });
34
+ }
35
+ const requestUrl = getRequestURL(event);
36
+ const targetUrl = new URL(requestUrl.pathname + requestUrl.search, authConfig.apiUrl);
37
+ const headers = new Headers();
38
+ for (const [name, value] of Object.entries(getHeaders(event))) {
39
+ if (value && ALLOWED_REQUEST_HEADERS.has(name.toLowerCase())) {
40
+ headers.set(name, Array.isArray(value) ? value.join(", ") : value);
41
+ }
42
+ }
43
+ headers.set("Authorization", `Bearer ${accessToken}`);
44
+ const method = event.method;
45
+ const body = method === "GET" || method === "HEAD" ? void 0 : await readRawBody(event);
46
+ const response = await fetch(targetUrl, {
47
+ body,
48
+ headers,
49
+ method
50
+ });
51
+ setResponseStatus(event, response.status, response.statusText);
52
+ for (const [name, value] of response.headers) {
53
+ if (ALLOWED_RESPONSE_HEADERS.has(name.toLowerCase())) {
54
+ setResponseHeader(event, name, value);
55
+ }
56
+ }
57
+ return await response.text();
58
+ });
@@ -8,7 +8,7 @@ export function createNuxtAuthClient(apiUrl, getAuthToken, getRefreshToken = ()
8
8
  "X-User-Agent": userAgent
9
9
  },
10
10
  onRequest: (context) => {
11
- const requestUrl = new URL(context.url);
11
+ const requestUrl = new URL(context.url, "http://localhost");
12
12
  const token = getAuthToken();
13
13
  const isTokenRequest = requestUrl.pathname.endsWith("/api/auth/token");
14
14
  if (token && !isTokenRequest) {
package/package.json CHANGED
@@ -1,63 +1,63 @@
1
1
  {
2
- "name": "@meistrari/auth-nuxt",
3
- "version": "3.7.0",
4
- "type": "module",
5
- "exports": {
6
- ".": {
7
- "types": "./dist/types.d.mts",
8
- "import": "./dist/module.mjs"
2
+ "name": "@meistrari/auth-nuxt",
3
+ "version": "3.8.1",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/types.d.mts",
8
+ "import": "./dist/module.mjs"
9
+ },
10
+ "./server/middleware/auth": {
11
+ "types": "./dist/runtime/server/middleware/auth.d.ts",
12
+ "import": "./dist/runtime/server/middleware/auth.js"
13
+ },
14
+ "./server/middleware/application-auth": {
15
+ "types": "./dist/runtime/server/middleware/application-auth.d.ts",
16
+ "import": "./dist/runtime/server/middleware/application-auth.js"
17
+ },
18
+ "./core": {
19
+ "types": "./dist/core.d.mts",
20
+ "import": "./dist/core.mjs"
21
+ }
9
22
  },
10
- "./server/middleware/auth": {
11
- "types": "./dist/runtime/server/middleware/auth.d.ts",
12
- "import": "./dist/runtime/server/middleware/auth.js"
23
+ "main": "./dist/module.mjs",
24
+ "typesVersions": {
25
+ "*": {
26
+ ".": [
27
+ "./dist/types.d.mts"
28
+ ]
29
+ }
13
30
  },
14
- "./server/middleware/application-auth": {
15
- "types": "./dist/runtime/server/middleware/application-auth.d.ts",
16
- "import": "./dist/runtime/server/middleware/application-auth.js"
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "scripts": {
35
+ "build": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build",
36
+ "docs": "nuxt-module-build prepare && typedoc"
17
37
  },
18
- "./core": {
19
- "types": "./dist/core.d.mts",
20
- "import": "./dist/core.mjs"
21
- }
22
- },
23
- "main": "./dist/module.mjs",
24
- "typesVersions": {
25
- "*": {
26
- ".": [
27
- "./dist/types.d.mts"
28
- ]
38
+ "dependencies": {
39
+ "@meistrari/auth-core": "1.19.0",
40
+ "jose": "6.1.3"
41
+ },
42
+ "peerDependencies": {
43
+ "nuxt": "^3.0.0 || ^4.0.0",
44
+ "vue": "^3.0.0"
45
+ },
46
+ "devDependencies": {
47
+ "@nuxt/devtools": "2.6.3",
48
+ "@nuxt/eslint-config": "1.9.0",
49
+ "@nuxt/kit": "4.0.3",
50
+ "@nuxt/module-builder": "1.0.2",
51
+ "@nuxt/schema": "4.0.3",
52
+ "@nuxt/test-utils": "3.19.2",
53
+ "@types/node": "latest",
54
+ "changelogen": "0.6.2",
55
+ "nuxt": "4.0.3",
56
+ "typescript": "5.9.2",
57
+ "unbuild": "3.6.1",
58
+ "typedoc": "0.28.18",
59
+ "typedoc-plugin-markdown": "4.11.0",
60
+ "vitest": "3.2.4",
61
+ "vue-tsc": "3.0.6"
29
62
  }
30
- },
31
- "files": [
32
- "dist"
33
- ],
34
- "scripts": {
35
- "build": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build",
36
- "docs": "nuxt-module-build prepare && typedoc"
37
- },
38
- "dependencies": {
39
- "@meistrari/auth-core": "workspace:*",
40
- "jose": "6.1.3"
41
- },
42
- "peerDependencies": {
43
- "nuxt": "^3.0.0 || ^4.0.0",
44
- "vue": "^3.0.0"
45
- },
46
- "devDependencies": {
47
- "@nuxt/devtools": "2.6.3",
48
- "@nuxt/eslint-config": "1.9.0",
49
- "@nuxt/kit": "4.0.3",
50
- "@nuxt/module-builder": "1.0.2",
51
- "@nuxt/schema": "4.0.3",
52
- "@nuxt/test-utils": "3.19.2",
53
- "@types/node": "latest",
54
- "changelogen": "0.6.2",
55
- "nuxt": "4.0.3",
56
- "typescript": "5.9.2",
57
- "unbuild": "3.6.1",
58
- "typedoc": "0.28.18",
59
- "typedoc-plugin-markdown": "4.11.0",
60
- "vitest": "3.2.4",
61
- "vue-tsc": "3.0.6"
62
- }
63
63
  }