@meistrari/auth-nuxt 4.1.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 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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@meistrari/auth-nuxt",
3
3
  "configKey": "telaAuth",
4
- "version": "4.1.0",
4
+ "version": "4.3.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
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.public.telaAuth = options;
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",
@@ -1,4 +1,4 @@
1
- import type { Session, SignInWithEmailAndPasswordOptions, SignInWithSamlOptions, SocialSignInOptions, User } from '@meistrari/auth-core';
1
+ import type { LoginMethod, Session, SignInWithEmailAndPasswordOptions, SignInWithSamlOptions, SocialSignInOptions, User } from '@meistrari/auth-core';
2
2
  import type { Ref } from 'vue';
3
3
  export interface UseTelaSessionReturn {
4
4
  /** Reactive reference to the current user. Null if not authenticated. */
@@ -23,6 +23,10 @@ export interface UseTelaSessionReturn {
23
23
  * @param options - Email/password sign-in configuration
24
24
  */
25
25
  signInWithEmailAndPassword: (options: SignInWithEmailAndPasswordOptions) => Promise<void>;
26
+ /**
27
+ * Lists the login methods enabled in the environment. Public; usable before authentication.
28
+ */
29
+ getLoginMethods: () => Promise<LoginMethod[]>;
26
30
  /**
27
31
  * Initiates social authentication flow with Google or Microsoft.
28
32
  * @param options - Social sign-in configuration
@@ -56,6 +56,9 @@ export function useTelaSession() {
56
56
  callbackURL
57
57
  });
58
58
  }
59
+ async function getLoginMethods() {
60
+ return await authClient.session.getLoginMethods();
61
+ }
59
62
  async function requestPasswordReset(email, callbackURL) {
60
63
  await authClient.session.requestPasswordReset(email, callbackURL);
61
64
  }
@@ -79,6 +82,7 @@ export function useTelaSession() {
79
82
  getSession,
80
83
  getToken,
81
84
  signInWithEmailAndPassword,
85
+ getLoginMethods,
82
86
  signInWithSocialProvider,
83
87
  signInWithSaml,
84
88
  signOut,
@@ -11,7 +11,7 @@ async function setApplicationAuthContext(event) {
11
11
  if (!token) {
12
12
  return;
13
13
  }
14
- const authConfig = useRuntimeConfig(event).public.telaAuth;
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).public.telaAuth;
9
+ const authConfig = useRuntimeConfig(event).telaAuth;
10
10
  const tokenCookie = getCookie(event, authConfig.jwtCookieName);
11
11
  if (!tokenCookie)
12
12
  return;
@@ -0,0 +1,3 @@
1
+ /** Publishes the resolved, browser-safe auth settings for each request's Nuxt payload. */
2
+ declare const _default: import("nitropack/types").NitroAppPlugin;
3
+ export default _default;
@@ -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).public.telaAuth;
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.public.telaAuth;
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().public.telaAuth;
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).public.telaAuth;
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.public.telaAuth;
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.public.telaAuth;
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.public.telaAuth;
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).public.telaAuth;
21
+ const authConfig = useRuntimeConfig(event).telaAuth;
22
22
  const { apiUrl, application } = authConfig;
23
23
  const { applicationId } = application ?? {};
24
24
  if (!applicationId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meistrari/auth-nuxt",
3
- "version": "4.1.0",
3
+ "version": "4.3.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -36,7 +36,7 @@
36
36
  "docs": "nuxt-module-build prepare && typedoc"
37
37
  },
38
38
  "dependencies": {
39
- "@meistrari/auth-core": "1.42.0",
39
+ "@meistrari/auth-core": "1.43.0",
40
40
  "jose": "6.1.3"
41
41
  },
42
42
  "peerDependencies": {