@meistrari/auth-nuxt 4.2.0 → 4.3.0
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 +46 -0
- package/dist/module.d.mts +7 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +21 -2
- package/dist/runtime/server/middleware/application-auth.js +1 -1
- package/dist/runtime/server/middleware/auth.js +1 -1
- package/dist/runtime/server/plugins/config.d.ts +3 -0
- package/dist/runtime/server/plugins/config.js +20 -0
- package/dist/runtime/server/routes/auth/api-key-proxy.js +1 -1
- package/dist/runtime/server/routes/auth/callback.js +2 -2
- package/dist/runtime/server/routes/auth/logout.js +1 -1
- package/dist/runtime/server/routes/auth/organization-proxy.js +1 -1
- package/dist/runtime/server/routes/auth/refresh.js +2 -2
- package/dist/runtime/server/routes/auth/switch-organization.js +2 -2
- package/dist/runtime/server/routes/auth/whoami.js +2 -2
- package/dist/runtime/server/utils/require-auth.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,6 +38,52 @@ Application auth auto-imports `useTelaApplicationAuth()` and the application-mod
|
|
|
38
38
|
|
|
39
39
|
First-party auth auto-imports `useTelaSession()`, `useTelaSessionAssurance()`, `useTelaOrganization()`, and `useTelaApiKey()`.
|
|
40
40
|
|
|
41
|
+
## Runtime configuration
|
|
42
|
+
|
|
43
|
+
Set deployment-specific values under `runtimeConfig.telaAuth`. These take precedence
|
|
44
|
+
over `telaAuth` module options, which provide defaults (including nested application settings).
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
export default defineNuxtConfig({
|
|
48
|
+
modules: ['@meistrari/auth-nuxt'],
|
|
49
|
+
telaAuth: {
|
|
50
|
+
application: { enabled: true },
|
|
51
|
+
},
|
|
52
|
+
runtimeConfig: {
|
|
53
|
+
telaAuth: {
|
|
54
|
+
apiUrl: '',
|
|
55
|
+
application: {
|
|
56
|
+
applicationId: '',
|
|
57
|
+
dashboardUrl: '',
|
|
58
|
+
redirectUri: '',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Override these values in the deployed server's environment without rebuilding:
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
NUXT_TELA_AUTH_API_URL=https://auth.example.com
|
|
69
|
+
NUXT_TELA_AUTH_JWT_COOKIE_NAME=my-jwt
|
|
70
|
+
NUXT_TELA_AUTH_APPLICATION_APPLICATION_ID=app_123
|
|
71
|
+
NUXT_TELA_AUTH_APPLICATION_DASHBOARD_URL=https://accounts.example.com
|
|
72
|
+
NUXT_TELA_AUTH_APPLICATION_REDIRECT_URI=https://app.example.com/auth/callback
|
|
73
|
+
NUXT_TELA_AUTH_APPLICATION_LOGIN_PATH=/login
|
|
74
|
+
NUXT_TELA_AUTH_APPLICATION_UNAUTHORIZED_PATH=/unauthorized
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The module declares these runtime keys even when omitted from your config. Server
|
|
78
|
+
handlers read `runtimeConfig.telaAuth`; the SDK copies its supported settings to
|
|
79
|
+
`runtimeConfig.public.telaAuth` per request for browser composables and plugins.
|
|
80
|
+
These settings are public: do not use them for credentials or secrets.
|
|
81
|
+
|
|
82
|
+
`application.enabled` and `skipServerMiddleware` select registrations at build time;
|
|
83
|
+
set them in `telaAuth` or `runtimeConfig.telaAuth` before building. Changing those
|
|
84
|
+
flags in the deployed environment cannot change which routes or plugins were built.
|
|
85
|
+
Static prerendered output retains the values from prerendering.
|
|
86
|
+
|
|
41
87
|
## API Reference
|
|
42
88
|
|
|
43
89
|
See it on [Pantry](https://pantry.tela.tools/ingredients/auth-nuxt/api)
|
package/dist/module.d.mts
CHANGED
|
@@ -57,6 +57,13 @@ interface ModuleOptions {
|
|
|
57
57
|
* and organization composables.
|
|
58
58
|
*/
|
|
59
59
|
declare const module$1: NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
60
|
+
declare module '@nuxt/schema' {
|
|
61
|
+
interface RuntimeConfig {
|
|
62
|
+
telaAuth: Partial<Omit<ModuleOptions, 'application'>> & {
|
|
63
|
+
application?: Partial<NonNullable<ModuleOptions['application']>>;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
60
67
|
|
|
61
68
|
export { module$1 as default };
|
|
62
69
|
export type { ModuleOptions };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, addImports, addComponent, addServerImportsDir, addServerHandler, addPlugin } from '@nuxt/kit';
|
|
1
|
+
import { defineNuxtModule, createResolver, addServerPlugin, addImports, addComponent, addServerImportsDir, addServerHandler, addPlugin } from '@nuxt/kit';
|
|
2
2
|
|
|
3
3
|
const module$1 = defineNuxtModule({
|
|
4
4
|
meta: {
|
|
@@ -6,12 +6,31 @@ const module$1 = defineNuxtModule({
|
|
|
6
6
|
configKey: "telaAuth"
|
|
7
7
|
},
|
|
8
8
|
defaults: {
|
|
9
|
+
apiUrl: "",
|
|
9
10
|
jwtCookieName: "tela-jwt",
|
|
10
11
|
skipServerMiddleware: false
|
|
11
12
|
},
|
|
12
13
|
setup(options, nuxt) {
|
|
13
14
|
const resolver = createResolver(import.meta.url);
|
|
14
|
-
nuxt.options.runtimeConfig.
|
|
15
|
+
const runtimeOptions = nuxt.options.runtimeConfig.telaAuth;
|
|
16
|
+
options = {
|
|
17
|
+
...options,
|
|
18
|
+
apiUrl: options.apiUrl ?? "",
|
|
19
|
+
...runtimeOptions,
|
|
20
|
+
application: {
|
|
21
|
+
enabled: false,
|
|
22
|
+
dashboardUrl: "",
|
|
23
|
+
applicationId: "",
|
|
24
|
+
redirectUri: "",
|
|
25
|
+
loginPath: "/login",
|
|
26
|
+
unauthorizedPath: "/unauthorized",
|
|
27
|
+
...options.application,
|
|
28
|
+
...runtimeOptions?.application
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
nuxt.options.runtimeConfig.telaAuth = options;
|
|
32
|
+
nuxt.options.runtimeConfig.public.telaAuth = { ...options };
|
|
33
|
+
addServerPlugin(resolver.resolve("./runtime/server/plugins/config"));
|
|
15
34
|
addImports({
|
|
16
35
|
name: "useTelaApiKey",
|
|
17
36
|
as: "useTelaApiKey",
|
|
@@ -11,7 +11,7 @@ async function setApplicationAuthContext(event) {
|
|
|
11
11
|
if (!token) {
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
-
const authConfig = useRuntimeConfig(event).
|
|
14
|
+
const authConfig = useRuntimeConfig(event).telaAuth;
|
|
15
15
|
const { apiUrl, application } = authConfig;
|
|
16
16
|
const { applicationId } = application ?? {};
|
|
17
17
|
if (!applicationId || !apiUrl) {
|
|
@@ -6,7 +6,7 @@ async function setAuthContext(event) {
|
|
|
6
6
|
user: null,
|
|
7
7
|
workspace: null
|
|
8
8
|
};
|
|
9
|
-
const authConfig = useRuntimeConfig(event).
|
|
9
|
+
const authConfig = useRuntimeConfig(event).telaAuth;
|
|
10
10
|
const tokenCookie = getCookie(event, authConfig.jwtCookieName);
|
|
11
11
|
if (!tokenCookie)
|
|
12
12
|
return;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineNitroPlugin, useRuntimeConfig } from "nitropack/runtime";
|
|
2
|
+
export default defineNitroPlugin((nitroApp) => {
|
|
3
|
+
nitroApp.hooks.hook("request", (event) => {
|
|
4
|
+
const config = useRuntimeConfig(event);
|
|
5
|
+
const { apiUrl, jwtCookieName, skipServerMiddleware, application } = config.telaAuth;
|
|
6
|
+
config.public.telaAuth = {
|
|
7
|
+
apiUrl,
|
|
8
|
+
jwtCookieName,
|
|
9
|
+
skipServerMiddleware,
|
|
10
|
+
application: application && {
|
|
11
|
+
enabled: application.enabled,
|
|
12
|
+
dashboardUrl: application.dashboardUrl,
|
|
13
|
+
applicationId: application.applicationId,
|
|
14
|
+
redirectUri: application.redirectUri,
|
|
15
|
+
loginPath: application.loginPath,
|
|
16
|
+
unauthorizedPath: application.unauthorizedPath
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -32,7 +32,7 @@ function getBearerToken(authorization) {
|
|
|
32
32
|
return value.slice("bearer ".length).trimStart() || void 0;
|
|
33
33
|
}
|
|
34
34
|
export default defineEventHandler(async (event) => {
|
|
35
|
-
const authConfig = useRuntimeConfig(event).
|
|
35
|
+
const authConfig = useRuntimeConfig(event).telaAuth;
|
|
36
36
|
const requestUrl = getRequestURL(event);
|
|
37
37
|
const requestHeaders = getHeaders(event);
|
|
38
38
|
const cookieAccessToken = getCookie(event, "tela-access-token");
|
|
@@ -5,8 +5,8 @@ export default defineEventHandler(async (event) => {
|
|
|
5
5
|
const query = getQuery(event);
|
|
6
6
|
const code = query.code;
|
|
7
7
|
const state = query.state;
|
|
8
|
-
const config = useRuntimeConfig();
|
|
9
|
-
const authConfig = config.
|
|
8
|
+
const config = useRuntimeConfig(event);
|
|
9
|
+
const authConfig = config.telaAuth;
|
|
10
10
|
const loginPath = authConfig.application?.loginPath ?? "/login";
|
|
11
11
|
if (!code || !state) {
|
|
12
12
|
console.error("[Auth Callback] Missing code or state parameter");
|
|
@@ -2,7 +2,7 @@ import { useRuntimeConfig } from "#imports";
|
|
|
2
2
|
import { defineEventHandler, deleteCookie, getCookie } from "h3";
|
|
3
3
|
import { createNuxtAuthClient } from "../../../shared.js";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
|
-
const authConfig = useRuntimeConfig().
|
|
5
|
+
const authConfig = useRuntimeConfig(event).telaAuth;
|
|
6
6
|
const refreshToken = getCookie(event, "tela-refresh-token");
|
|
7
7
|
deleteCookie(event, "tela-access-token", { path: "/" });
|
|
8
8
|
deleteCookie(event, "tela-refresh-token", { path: "/" });
|
|
@@ -49,7 +49,7 @@ function getBearerToken(authorization) {
|
|
|
49
49
|
return value.slice("bearer ".length).trimStart() || void 0;
|
|
50
50
|
}
|
|
51
51
|
export default defineEventHandler(async (event) => {
|
|
52
|
-
const authConfig = useRuntimeConfig(event).
|
|
52
|
+
const authConfig = useRuntimeConfig(event).telaAuth;
|
|
53
53
|
const requestUrl = getRequestURL(event);
|
|
54
54
|
const requestHeaders = getHeaders(event);
|
|
55
55
|
const cookieAccessToken = getCookie(event, "tela-access-token");
|
|
@@ -4,8 +4,8 @@ import { parseTokenExpiry } from "../../../helpers/token.js";
|
|
|
4
4
|
import { createNuxtAuthClient } from "../../../shared.js";
|
|
5
5
|
import { planRefreshFailure, shouldWriteTokens } from "../../utils/refresh-upstream.js";
|
|
6
6
|
export default defineEventHandler(async (event) => {
|
|
7
|
-
const config = useRuntimeConfig();
|
|
8
|
-
const authConfig = config.
|
|
7
|
+
const config = useRuntimeConfig(event);
|
|
8
|
+
const authConfig = config.telaAuth;
|
|
9
9
|
const refreshToken = getCookie(event, "tela-refresh-token");
|
|
10
10
|
if (!refreshToken) {
|
|
11
11
|
throw createError({
|
|
@@ -2,8 +2,8 @@ import { createError, useRuntimeConfig } from "#imports";
|
|
|
2
2
|
import { defineEventHandler, getCookie, readBody, setCookie } from "h3";
|
|
3
3
|
import { createNuxtAuthClient } from "../../../shared.js";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
|
-
const config = useRuntimeConfig();
|
|
6
|
-
const authConfig = config.
|
|
5
|
+
const config = useRuntimeConfig(event);
|
|
6
|
+
const authConfig = config.telaAuth;
|
|
7
7
|
const accessToken = getCookie(event, "tela-access-token");
|
|
8
8
|
if (!accessToken) {
|
|
9
9
|
throw createError({
|
|
@@ -2,8 +2,8 @@ import { createError, useRuntimeConfig } from "#imports";
|
|
|
2
2
|
import { defineEventHandler, getCookie } from "h3";
|
|
3
3
|
import { createNuxtAuthClient } from "../../../shared.js";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
|
-
const config = useRuntimeConfig();
|
|
6
|
-
const authConfig = config.
|
|
5
|
+
const config = useRuntimeConfig(event);
|
|
6
|
+
const authConfig = config.telaAuth;
|
|
7
7
|
const authClient = createNuxtAuthClient(authConfig.apiUrl, () => null);
|
|
8
8
|
const accessToken = getCookie(event, "tela-access-token");
|
|
9
9
|
if (!accessToken) {
|
|
@@ -18,7 +18,7 @@ export function requireAuth(handler, options) {
|
|
|
18
18
|
return await handler(event);
|
|
19
19
|
}
|
|
20
20
|
const token = getCookie(event, "tela-access-token");
|
|
21
|
-
const authConfig = useRuntimeConfig(event).
|
|
21
|
+
const authConfig = useRuntimeConfig(event).telaAuth;
|
|
22
22
|
const { apiUrl, application } = authConfig;
|
|
23
23
|
const { applicationId } = application ?? {};
|
|
24
24
|
if (!applicationId) {
|