@lumoauth/nextjs 1.4.0 → 1.4.2

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
@@ -31,6 +31,7 @@ It is part of the [LumoAuth JavaScript SDK](../../README.md).
31
31
  - [Call LumoAuth or your API with the user's token](#call-lumoauth-or-your-api-with-the-users-token)
32
32
  - [Use components and hooks in client components](#use-components-and-hooks-in-client-components)
33
33
  - [Request more scopes](#request-more-scopes)
34
+ - [The callback URL](#the-callback-url)
34
35
  - [How the session is protected](#how-the-session-is-protected)
35
36
  - [Sessions and access tokens](#sessions-and-access-tokens)
36
37
  - [API reference](#api-reference)
@@ -56,7 +57,8 @@ It is part of the [LumoAuth JavaScript SDK](../../README.md).
56
57
  - Node 18 or newer. The cookie code uses Web Crypto, so it also runs in the edge runtime.
57
58
  - A LumoAuth organization and an OAuth client. Register the callback URL
58
59
  (`<your origin>/api/auth/callback`) as a redirect URI. Register your sign-out landing page
59
- (by default `<your origin>/`) as a post-logout redirect URI.
60
+ (by default `<your origin>/`) as a post-logout redirect URI. See
61
+ [The callback URL](#the-callback-url).
60
62
 
61
63
  ## Install
62
64
 
@@ -73,10 +75,10 @@ with this package.
73
75
 
74
76
  ```bash
75
77
  # .env.local
76
- NEXT_PUBLIC_LUMOAUTH_DOMAIN=https://app.lumoauth.dev # EU region: https://eu.app.lumoauth.dev
77
78
  NEXT_PUBLIC_LUMOAUTH_ORG_ID=acme-corp
78
79
  NEXT_PUBLIC_LUMOAUTH_CLIENT_ID=your-client-id
79
- NEXT_PUBLIC_REDIRECT_URI=http://localhost:3000/api/auth/callback
80
+ # Only for an organization in the EU region. The default is https://app.lumoauth.dev (US).
81
+ # NEXT_PUBLIC_LUMOAUTH_DOMAIN=https://eu.app.lumoauth.dev
80
82
 
81
83
  # Encrypts the session cookie. Server only. At least 32 characters: openssl rand -hex 32
82
84
  LUMOAUTH_SECRET=replace-with-64-hex-characters
@@ -134,6 +136,10 @@ to a page after sign-in, add `?return_to=/path`.
134
136
  with PKCE. It stores the tokens in a cookie named `lumo_session`. The cookie is encrypted, so the
135
137
  browser cannot read or change it. The refresh token never leaves your server.
136
138
 
139
+ **The callback path is fixed, the address is not.** The sign-in response always comes back to
140
+ `/api/auth/callback` on the address that the browser used. No environment variable names that
141
+ URL. See [The callback URL](#the-callback-url).
142
+
137
143
  **The session outlives the access token.** A session lasts 30 days by default. An access token
138
144
  lasts about an hour. The middleware replaces the access token when it is about to expire. See
139
145
  [Sessions and access tokens](#sessions-and-access-tokens).
@@ -153,10 +159,10 @@ environment.
153
159
 
154
160
  | Option | Environment variable | Required | Default | Description |
155
161
  |---|---|---|---|---|
156
- | `domain` | `NEXT_PUBLIC_LUMOAUTH_DOMAIN` | yes | none | Root URL of LumoAuth |
162
+ | `domain` | `NEXT_PUBLIC_LUMOAUTH_DOMAIN` | no | `https://app.lumoauth.dev` | Root URL of the region. EU: `https://eu.app.lumoauth.dev` |
157
163
  | `orgId` | `NEXT_PUBLIC_LUMOAUTH_ORG_ID` | yes | none | Organization slug |
158
164
  | `clientId` | `NEXT_PUBLIC_LUMOAUTH_CLIENT_ID` | yes | none | OAuth client ID |
159
- | `redirectUri` | `NEXT_PUBLIC_REDIRECT_URI` | yes | none | Absolute callback URL, registered on the client |
165
+ | `redirectUri` | `NEXT_PUBLIC_REDIRECT_URI` | no | `<origin>/api/auth/callback` of each request | Pins the callback URL, and the origin of every redirect back to the app. See [The callback URL](#the-callback-url). |
160
166
  | `secret` | `LUMOAUTH_SECRET` | yes | none | Encrypts the session cookie. At least 32 characters. |
161
167
  | `clientSecret` | `LUMOAUTH_CLIENT_SECRET` | confidential clients only | none | Never give it a `NEXT_PUBLIC_` prefix. |
162
168
  | `afterSignInUrl` | none | no | `'/'` | Where a user goes after sign-in when there is no `return_to` |
@@ -166,7 +172,8 @@ environment.
166
172
 
167
173
  The public values use the `NEXT_PUBLIC_` prefix, so the client provider and the server read the
168
174
  same names. The two secrets do not, because Next.js puts every `NEXT_PUBLIC_` value into the
169
- browser bundle. A missing required value throws an error that names it.
175
+ browser bundle. A missing required value throws an error that names it. An empty variable counts
176
+ as unset.
170
177
 
171
178
  Pass the same overrides everywhere when you do not use environment variables:
172
179
 
@@ -236,18 +243,15 @@ their own. Your API must still check the token and the user's permissions.
236
243
 
237
244
  ```ts
238
245
  // app/api/documents/[id]/route.ts
239
- import { auth } from '@lumoauth/nextjs/server';
246
+ import { auth, resolveConfig } from '@lumoauth/nextjs/server';
240
247
  import { LumoAuth } from '@lumoauth/client';
241
248
 
242
249
  export async function DELETE(req: Request) {
243
250
  const token = (await auth()).getToken();
244
251
  if (!token) return new Response('Unauthorized', { status: 401 });
245
252
 
246
- const lumo = new LumoAuth({
247
- baseUrl: process.env.NEXT_PUBLIC_LUMOAUTH_DOMAIN!,
248
- orgId: process.env.NEXT_PUBLIC_LUMOAUTH_ORG_ID!,
249
- token,
250
- });
253
+ const { domain, orgId } = resolveConfig();
254
+ const lumo = new LumoAuth({ baseUrl: domain, orgId, token });
251
255
  if (!(await lumo.permissions.check('document.delete'))) {
252
256
  return new Response('Forbidden', { status: 403 });
253
257
  }
@@ -263,7 +267,8 @@ above covers API routes.
263
267
  ### Use components and hooks in client components
264
268
 
265
269
  Wrap the app in `<LumoAuthNextProvider>`. It takes the same props as `<LumoAuthProvider>` from
266
- `@lumoauth/react`, except `storage`, plus `basePath`.
270
+ `@lumoauth/react`, except `storage`, plus `basePath`. `domain` is optional and defaults to
271
+ `https://app.lumoauth.dev`.
267
272
 
268
273
  ```tsx
269
274
  // app/providers.tsx
@@ -273,7 +278,7 @@ import { LumoAuthNextProvider } from '@lumoauth/nextjs';
273
278
  export function Providers({ children }: { children: React.ReactNode }) {
274
279
  return (
275
280
  <LumoAuthNextProvider
276
- domain={process.env.NEXT_PUBLIC_LUMOAUTH_DOMAIN!}
281
+ domain={process.env.NEXT_PUBLIC_LUMOAUTH_DOMAIN}
277
282
  orgId={process.env.NEXT_PUBLIC_LUMOAUTH_ORG_ID!}
278
283
  clientId={process.env.NEXT_PUBLIC_LUMOAUTH_CLIENT_ID!}
279
284
  >
@@ -338,6 +343,30 @@ export const { GET, POST } = createRouteHandler({
338
343
  The new scopes apply after the user signs in again. The full table is in the
339
344
  [client README](../client/README.md#scopes).
340
345
 
346
+ ### The callback URL
347
+
348
+ The route handler sends `<origin>/api/auth/callback` as the redirect URI. `<origin>` is the
349
+ address in the browser. The handler reads it from the `X-Forwarded-Host` and
350
+ `X-Forwarded-Proto` headers, which Next.js sets on every request, or from the `Host` header.
351
+ `request.url` is not used, because a Next.js server behind a proxy sees its own address there,
352
+ such as `http://localhost:3000`. Auth.js and nextjs-auth0 read the same headers.
353
+
354
+ So one build signs in on `http://localhost:3000`, on a preview deployment and in production.
355
+ For each address, register two URLs on the OAuth client:
356
+
357
+ | Portal field | Value |
358
+ |---|---|
359
+ | **Configuration → Redirect URIs** | `<origin>/api/auth/callback` |
360
+ | **Configuration → Logout → Post-logout redirect URIs** | `<origin>/` (`<origin><afterSignOutUrl>`) |
361
+
362
+ LumoAuth compares redirect URIs exactly: scheme, host, port and path. When an address is not
363
+ registered, LumoAuth shows an **Invalid Redirect URL** page that names the URL to add.
364
+
365
+ To pin the app to one address, set `NEXT_PUBLIC_REDIRECT_URI` to the full callback URL, for
366
+ example `https://app.example.com/api/auth/callback`. Its origin then also becomes the origin of
367
+ the redirects after sign-in and sign-out. Pin it when a proxy in front of the app sends neither
368
+ `X-Forwarded-Host` nor the public `Host` header.
369
+
341
370
  ## How the session is protected
342
371
 
343
372
  The cookie is encrypted and authenticated with AES-256-GCM, using a key derived from
@@ -429,6 +458,9 @@ the build)
429
458
  | `getToken()` returns `null` while `isSignedIn` is `true` | The access token expired and no middleware ran on this route. | Install `lumoAuthMiddleware()` and make sure its `matcher` covers the route. |
430
459
  | After sign-in the user lands on `afterSignOutUrl` | The callback failed. The `state` did not match, the PKCE cookie expired after 10 minutes, or the code exchange failed. | Start sign-in again. Check that the redirect URI and the client secret are correct. |
431
460
  | After sign-out the user is still signed in at LumoAuth | `<origin><afterSignOutUrl>` is not a registered post-logout redirect URI. | Register it on the OAuth client. |
461
+ | LumoAuth shows **Invalid Redirect URL** | The callback URL of this address is not registered. | Add the URL that the page names under **Configuration → Redirect URIs**. See [The callback URL](#the-callback-url). |
462
+ | After sign-in the browser goes to `http://localhost:3000` instead of the public address | A proxy in front of the app sends neither `X-Forwarded-Host` nor the public `Host`. | Set `NEXT_PUBLIC_REDIRECT_URI` to the public callback URL. |
463
+ | The login page does not load inside a preview frame | LumoAuth's login page cannot be shown in a frame, and the session cookie is not sent in a frame of another site. | Open the app in its own browser tab. |
432
464
  | A `403` with `requiredScopes`, such as `['authz:read']` | The token lacks a scope. | Add the scope to `scope` and sign in again. |
433
465
  | Hooks show the user as signed out after `<SignInButton>` | A browser sign-in cannot save tokens into the cookie session. | Link to `/api/auth/login` instead. |
434
466
  | The cookie stops working after you change `LUMOAUTH_SECRET` | The old cookie cannot be decrypted. | This is expected. The middleware clears the cookie and the user signs in again. |
package/dist/index.d.mts CHANGED
@@ -2,7 +2,12 @@ import { LumoAuthProviderProps } from '@lumoauth/react';
2
2
  export { AppearanceProps, AuthCallback, AuthCallbackProps, AuthState, AuthStatus, LumoAuth, LumoAuthConfig, LumoAuthContextValue, LumoAuthProvider, LumoAuthProviderProps, LumoAuthUser, Protect, ProtectProps, RedirectToSignIn, RedirectToSignInProps, SignIn, SignInButton, SignInButtonProps, SignInProps, SignOutButton, SignOutButtonProps, SignUp, SignUpButton, SignUpButtonProps, SignUpProps, SignedIn, SignedInProps, SignedOut, SignedOutProps, UseEmailFirstReturn, UseMagicLinkReturn, UserAvatar, UserAvatarProps, UserButton, UserButtonProps, UserProfile, UserProfileProps, useAbac, useAuth, useEmailFirst, useLumoAuth, useMagicLink, usePermission, useSession, useSignIn, useUser, useZanzibar } from '@lumoauth/react';
3
3
  import * as react from 'react';
4
4
 
5
- type LumoAuthNextProviderProps = Omit<LumoAuthProviderProps, 'storage'> & {
5
+ type LumoAuthNextProviderProps = Omit<LumoAuthProviderProps, 'storage' | 'domain'> & {
6
+ /**
7
+ * Base URL of the LumoAuth region of the organization.
8
+ * @default 'https://app.lumoauth.dev' (US). EU: 'https://eu.app.lumoauth.dev'.
9
+ */
10
+ domain?: string;
6
11
  /** Base path where createRouteHandler is mounted. @default '/api/auth' */
7
12
  basePath?: string;
8
13
  };
@@ -14,6 +19,6 @@ type LumoAuthNextProviderProps = Omit<LumoAuthProviderProps, 'storage'> & {
14
19
  * after hydration. This one reads the session from the httpOnly cookie via the
15
20
  * route handler, matching what `auth()` already rendered on the server.
16
21
  */
17
- declare function LumoAuthNextProvider({ basePath, children, ...rest }: LumoAuthNextProviderProps): react.JSX.Element;
22
+ declare function LumoAuthNextProvider({ basePath, domain, children, ...rest }: LumoAuthNextProviderProps): react.JSX.Element;
18
23
 
19
24
  export { LumoAuthNextProvider };
package/dist/index.d.ts CHANGED
@@ -2,7 +2,12 @@ import { LumoAuthProviderProps } from '@lumoauth/react';
2
2
  export { AppearanceProps, AuthCallback, AuthCallbackProps, AuthState, AuthStatus, LumoAuth, LumoAuthConfig, LumoAuthContextValue, LumoAuthProvider, LumoAuthProviderProps, LumoAuthUser, Protect, ProtectProps, RedirectToSignIn, RedirectToSignInProps, SignIn, SignInButton, SignInButtonProps, SignInProps, SignOutButton, SignOutButtonProps, SignUp, SignUpButton, SignUpButtonProps, SignUpProps, SignedIn, SignedInProps, SignedOut, SignedOutProps, UseEmailFirstReturn, UseMagicLinkReturn, UserAvatar, UserAvatarProps, UserButton, UserButtonProps, UserProfile, UserProfileProps, useAbac, useAuth, useEmailFirst, useLumoAuth, useMagicLink, usePermission, useSession, useSignIn, useUser, useZanzibar } from '@lumoauth/react';
3
3
  import * as react from 'react';
4
4
 
5
- type LumoAuthNextProviderProps = Omit<LumoAuthProviderProps, 'storage'> & {
5
+ type LumoAuthNextProviderProps = Omit<LumoAuthProviderProps, 'storage' | 'domain'> & {
6
+ /**
7
+ * Base URL of the LumoAuth region of the organization.
8
+ * @default 'https://app.lumoauth.dev' (US). EU: 'https://eu.app.lumoauth.dev'.
9
+ */
10
+ domain?: string;
6
11
  /** Base path where createRouteHandler is mounted. @default '/api/auth' */
7
12
  basePath?: string;
8
13
  };
@@ -14,6 +19,6 @@ type LumoAuthNextProviderProps = Omit<LumoAuthProviderProps, 'storage'> & {
14
19
  * after hydration. This one reads the session from the httpOnly cookie via the
15
20
  * route handler, matching what `auth()` already rendered on the server.
16
21
  */
17
- declare function LumoAuthNextProvider({ basePath, children, ...rest }: LumoAuthNextProviderProps): react.JSX.Element;
22
+ declare function LumoAuthNextProvider({ basePath, domain, children, ...rest }: LumoAuthNextProviderProps): react.JSX.Element;
18
23
 
19
24
  export { LumoAuthNextProvider };
package/dist/index.js CHANGED
@@ -63,9 +63,19 @@ var import_react10 = require("@lumoauth/react");
63
63
  var import_react = require("react");
64
64
  var import_react2 = require("@lumoauth/react");
65
65
  var import_client = require("@lumoauth/client");
66
- var import_jsx_runtime = require("react/jsx-runtime");
66
+
67
+ // src/defaults.ts
68
+ var DEFAULT_DOMAIN = "https://app.lumoauth.dev";
69
+
70
+ // src/provider.tsx
71
+ var import_jsx_runtime = (
72
+ // `||`, not a parameter default: an unset NEXT_PUBLIC_ variable can
73
+ // arrive as an empty string.
74
+ require("react/jsx-runtime")
75
+ );
67
76
  function LumoAuthNextProvider({
68
77
  basePath = "/api/auth",
78
+ domain,
69
79
  children,
70
80
  ...rest
71
81
  }) {
@@ -76,7 +86,7 @@ function LumoAuthNextProvider({
76
86
  }),
77
87
  [basePath]
78
88
  );
79
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react2.LumoAuthProvider, { ...rest, storage, children });
89
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react2.LumoAuthProvider, { ...rest, domain: domain || DEFAULT_DOMAIN, storage, children });
80
90
  }
81
91
  // Annotate the CommonJS export names for ESM import in node:
82
92
  0 && (module.exports = {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/provider.tsx"],"sourcesContent":["'use client';\n\n// @lumoauth/nextjs — client entry.\n//\n// Re-exports the React SDK so a Next.js app needs one dependency. Everything\n// server-side (auth, currentUser, route handlers, middleware) lives in\n// @lumoauth/nextjs/server, which is never bundled for the browser.\n\n// Named re-exports, not `export *`: Next 14 rejects `export *` in a module\n// carrying the \"use client\" directive. Keep this list in sync with\n// @lumoauth/react's index.\nexport { LumoAuth, type LumoAuthConfig } from '@lumoauth/react';\n\n// Provider\nexport { LumoAuthProvider } from '@lumoauth/react';\n\n// Authentication Components\nexport { SignIn, SignUp, AuthCallback } from '@lumoauth/react';\n\n// User Components\nexport { UserButton, UserAvatar, UserProfile } from '@lumoauth/react';\n\n// Authorization Components\nexport { Protect } from '@lumoauth/react';\n\n// Control Components\nexport { SignedIn, SignedOut, RedirectToSignIn } from '@lumoauth/react';\n\n// Unstyled Components\nexport { SignInButton, SignUpButton, SignOutButton } from '@lumoauth/react';\n\n// Hooks\nexport {\n useAuth,\n useUser,\n useSignIn,\n useSession,\n useLumoAuth,\n usePermission,\n useZanzibar,\n useAbac,\n useMagicLink,\n useEmailFirst,\n} from '@lumoauth/react';\n\n// Types\nexport type {\n LumoAuthProviderProps,\n LumoAuthUser,\n AuthState,\n AuthStatus,\n LumoAuthContextValue,\n SignInProps,\n SignUpProps,\n UserButtonProps,\n UserAvatarProps,\n UserProfileProps,\n ProtectProps,\n AppearanceProps,\n AuthCallbackProps,\n SignedInProps,\n SignedOutProps,\n SignInButtonProps,\n SignUpButtonProps,\n SignOutButtonProps,\n RedirectToSignInProps,\n UseMagicLinkReturn,\n UseEmailFirstReturn,\n} from '@lumoauth/react';\n\nexport { LumoAuthNextProvider } from './provider';\n","'use client';\n\nimport { useMemo } from 'react';\nimport { LumoAuthProvider, type LumoAuthProviderProps } from '@lumoauth/react';\nimport { cookieStorageAdapter } from '@lumoauth/client';\n\nexport type LumoAuthNextProviderProps = Omit<LumoAuthProviderProps, 'storage'> & {\n /** Base path where createRouteHandler is mounted. @default '/api/auth' */\n basePath?: string;\n};\n\n/**\n * Provider wired to the server-side session.\n *\n * The plain `<LumoAuthProvider>` keeps tokens in web storage, which the server\n * cannot see — so a page always renders signed-out first and corrects itself\n * after hydration. This one reads the session from the httpOnly cookie via the\n * route handler, matching what `auth()` already rendered on the server.\n */\nexport function LumoAuthNextProvider({\n basePath = '/api/auth',\n children,\n ...rest\n}: LumoAuthNextProviderProps) {\n // Memoised: `storage` is a dependency of the provider's session useMemo, so\n // a new adapter each render would rebuild the session every render.\n const storage = useMemo(\n () =>\n cookieStorageAdapter({\n sessionEndpoint: `${basePath}/session`,\n logoutEndpoint: `${basePath}/logout`,\n }),\n [basePath],\n );\n\n return (\n <LumoAuthProvider {...rest} storage={storage}>\n {children}\n </LumoAuthProvider>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,IAAAA,gBAA8C;AAG9C,IAAAA,gBAAiC;AAGjC,IAAAA,gBAA6C;AAG7C,IAAAA,gBAAoD;AAGpD,IAAAA,gBAAwB;AAGxB,IAAAA,gBAAsD;AAGtD,IAAAA,gBAA0D;AAG1D,IAAAA,iBAWO;;;ACzCP,mBAAwB;AACxB,IAAAC,gBAA6D;AAC7D,oBAAqC;AAgC7B;AAjBD,SAAS,qBAAqB;AAAA,EACjC,WAAW;AAAA,EACX;AAAA,EACA,GAAG;AACP,GAA8B;AAG1B,QAAM,cAAU;AAAA,IACZ,UACI,oCAAqB;AAAA,MACjB,iBAAiB,GAAG,QAAQ;AAAA,MAC5B,gBAAgB,GAAG,QAAQ;AAAA,IAC/B,CAAC;AAAA,IACL,CAAC,QAAQ;AAAA,EACb;AAEA,SACI,4CAAC,kCAAkB,GAAG,MAAM,SACvB,UACL;AAER;","names":["import_react","import_react"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/provider.tsx","../src/defaults.ts"],"sourcesContent":["'use client';\n\n// @lumoauth/nextjs — client entry.\n//\n// Re-exports the React SDK so a Next.js app needs one dependency. Everything\n// server-side (auth, currentUser, route handlers, middleware) lives in\n// @lumoauth/nextjs/server, which is never bundled for the browser.\n\n// Named re-exports, not `export *`: Next 14 rejects `export *` in a module\n// carrying the \"use client\" directive. Keep this list in sync with\n// @lumoauth/react's index.\nexport { LumoAuth, type LumoAuthConfig } from '@lumoauth/react';\n\n// Provider\nexport { LumoAuthProvider } from '@lumoauth/react';\n\n// Authentication Components\nexport { SignIn, SignUp, AuthCallback } from '@lumoauth/react';\n\n// User Components\nexport { UserButton, UserAvatar, UserProfile } from '@lumoauth/react';\n\n// Authorization Components\nexport { Protect } from '@lumoauth/react';\n\n// Control Components\nexport { SignedIn, SignedOut, RedirectToSignIn } from '@lumoauth/react';\n\n// Unstyled Components\nexport { SignInButton, SignUpButton, SignOutButton } from '@lumoauth/react';\n\n// Hooks\nexport {\n useAuth,\n useUser,\n useSignIn,\n useSession,\n useLumoAuth,\n usePermission,\n useZanzibar,\n useAbac,\n useMagicLink,\n useEmailFirst,\n} from '@lumoauth/react';\n\n// Types\nexport type {\n LumoAuthProviderProps,\n LumoAuthUser,\n AuthState,\n AuthStatus,\n LumoAuthContextValue,\n SignInProps,\n SignUpProps,\n UserButtonProps,\n UserAvatarProps,\n UserProfileProps,\n ProtectProps,\n AppearanceProps,\n AuthCallbackProps,\n SignedInProps,\n SignedOutProps,\n SignInButtonProps,\n SignUpButtonProps,\n SignOutButtonProps,\n RedirectToSignInProps,\n UseMagicLinkReturn,\n UseEmailFirstReturn,\n} from '@lumoauth/react';\n\nexport { LumoAuthNextProvider } from './provider';\n","'use client';\n\nimport { useMemo } from 'react';\nimport { LumoAuthProvider, type LumoAuthProviderProps } from '@lumoauth/react';\nimport { cookieStorageAdapter } from '@lumoauth/client';\nimport { DEFAULT_DOMAIN } from './defaults';\n\nexport type LumoAuthNextProviderProps = Omit<LumoAuthProviderProps, 'storage' | 'domain'> & {\n /**\n * Base URL of the LumoAuth region of the organization.\n * @default 'https://app.lumoauth.dev' (US). EU: 'https://eu.app.lumoauth.dev'.\n */\n domain?: string;\n /** Base path where createRouteHandler is mounted. @default '/api/auth' */\n basePath?: string;\n};\n\n/**\n * Provider wired to the server-side session.\n *\n * The plain `<LumoAuthProvider>` keeps tokens in web storage, which the server\n * cannot see — so a page always renders signed-out first and corrects itself\n * after hydration. This one reads the session from the httpOnly cookie via the\n * route handler, matching what `auth()` already rendered on the server.\n */\nexport function LumoAuthNextProvider({\n basePath = '/api/auth',\n domain,\n children,\n ...rest\n}: LumoAuthNextProviderProps) {\n // Memoised: `storage` is a dependency of the provider's session useMemo, so\n // a new adapter each render would rebuild the session every render.\n const storage = useMemo(\n () =>\n cookieStorageAdapter({\n sessionEndpoint: `${basePath}/session`,\n logoutEndpoint: `${basePath}/logout`,\n }),\n [basePath],\n );\n\n return (\n // `||`, not a parameter default: an unset NEXT_PUBLIC_ variable can\n // arrive as an empty string.\n <LumoAuthProvider {...rest} domain={domain || DEFAULT_DOMAIN} storage={storage}>\n {children}\n </LumoAuthProvider>\n );\n}\n","// Shared by the client and the server entry, so it must not import anything\n// server-only.\n\n/** US region. EU organizations set NEXT_PUBLIC_LUMOAUTH_DOMAIN=https://eu.app.lumoauth.dev. */\nexport const DEFAULT_DOMAIN = 'https://app.lumoauth.dev';\n\n/**\n * Where `createRouteHandler()` receives the authorization response. Fixed,\n * like the login path that the middleware and `protectPage()` redirect to,\n * so the URL to register is always `{app origin}/api/auth/callback`.\n */\nexport const CALLBACK_PATH = '/api/auth/callback';\n\n/** The login route of `createRouteHandler()`. */\nexport const LOGIN_PATH = '/api/auth/login';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,IAAAA,gBAA8C;AAG9C,IAAAA,gBAAiC;AAGjC,IAAAA,gBAA6C;AAG7C,IAAAA,gBAAoD;AAGpD,IAAAA,gBAAwB;AAGxB,IAAAA,gBAAsD;AAGtD,IAAAA,gBAA0D;AAG1D,IAAAA,iBAWO;;;ACzCP,mBAAwB;AACxB,IAAAC,gBAA6D;AAC7D,oBAAqC;;;ACA9B,IAAM,iBAAiB;;;ADyCtB;AAAA;AAAA;AAAA;AAAA;AApBD,SAAS,qBAAqB;AAAA,EACjC,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EACA,GAAG;AACP,GAA8B;AAG1B,QAAM,cAAU;AAAA,IACZ,UACI,oCAAqB;AAAA,MACjB,iBAAiB,GAAG,QAAQ;AAAA,MAC5B,gBAAgB,GAAG,QAAQ;AAAA,IAC/B,CAAC;AAAA,IACL,CAAC,QAAQ;AAAA,EACb;AAEA,SAGI,4CAAC,kCAAkB,GAAG,MAAM,QAAQ,UAAU,gBAAgB,SACzD,UACL;AAER;","names":["import_react","import_react"]}
package/dist/index.mjs CHANGED
@@ -26,9 +26,15 @@ import {
26
26
  import { useMemo } from "react";
27
27
  import { LumoAuthProvider } from "@lumoauth/react";
28
28
  import { cookieStorageAdapter } from "@lumoauth/client";
29
+
30
+ // src/defaults.ts
31
+ var DEFAULT_DOMAIN = "https://app.lumoauth.dev";
32
+
33
+ // src/provider.tsx
29
34
  import { jsx } from "react/jsx-runtime";
30
35
  function LumoAuthNextProvider({
31
36
  basePath = "/api/auth",
37
+ domain,
32
38
  children,
33
39
  ...rest
34
40
  }) {
@@ -39,7 +45,11 @@ function LumoAuthNextProvider({
39
45
  }),
40
46
  [basePath]
41
47
  );
42
- return /* @__PURE__ */ jsx(LumoAuthProvider, { ...rest, storage, children });
48
+ return (
49
+ // `||`, not a parameter default: an unset NEXT_PUBLIC_ variable can
50
+ // arrive as an empty string.
51
+ /* @__PURE__ */ jsx(LumoAuthProvider, { ...rest, domain: domain || DEFAULT_DOMAIN, storage, children })
52
+ );
43
53
  }
44
54
  export {
45
55
  AuthCallback,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/provider.tsx"],"sourcesContent":["'use client';\n\n// @lumoauth/nextjs — client entry.\n//\n// Re-exports the React SDK so a Next.js app needs one dependency. Everything\n// server-side (auth, currentUser, route handlers, middleware) lives in\n// @lumoauth/nextjs/server, which is never bundled for the browser.\n\n// Named re-exports, not `export *`: Next 14 rejects `export *` in a module\n// carrying the \"use client\" directive. Keep this list in sync with\n// @lumoauth/react's index.\nexport { LumoAuth, type LumoAuthConfig } from '@lumoauth/react';\n\n// Provider\nexport { LumoAuthProvider } from '@lumoauth/react';\n\n// Authentication Components\nexport { SignIn, SignUp, AuthCallback } from '@lumoauth/react';\n\n// User Components\nexport { UserButton, UserAvatar, UserProfile } from '@lumoauth/react';\n\n// Authorization Components\nexport { Protect } from '@lumoauth/react';\n\n// Control Components\nexport { SignedIn, SignedOut, RedirectToSignIn } from '@lumoauth/react';\n\n// Unstyled Components\nexport { SignInButton, SignUpButton, SignOutButton } from '@lumoauth/react';\n\n// Hooks\nexport {\n useAuth,\n useUser,\n useSignIn,\n useSession,\n useLumoAuth,\n usePermission,\n useZanzibar,\n useAbac,\n useMagicLink,\n useEmailFirst,\n} from '@lumoauth/react';\n\n// Types\nexport type {\n LumoAuthProviderProps,\n LumoAuthUser,\n AuthState,\n AuthStatus,\n LumoAuthContextValue,\n SignInProps,\n SignUpProps,\n UserButtonProps,\n UserAvatarProps,\n UserProfileProps,\n ProtectProps,\n AppearanceProps,\n AuthCallbackProps,\n SignedInProps,\n SignedOutProps,\n SignInButtonProps,\n SignUpButtonProps,\n SignOutButtonProps,\n RedirectToSignInProps,\n UseMagicLinkReturn,\n UseEmailFirstReturn,\n} from '@lumoauth/react';\n\nexport { LumoAuthNextProvider } from './provider';\n","'use client';\n\nimport { useMemo } from 'react';\nimport { LumoAuthProvider, type LumoAuthProviderProps } from '@lumoauth/react';\nimport { cookieStorageAdapter } from '@lumoauth/client';\n\nexport type LumoAuthNextProviderProps = Omit<LumoAuthProviderProps, 'storage'> & {\n /** Base path where createRouteHandler is mounted. @default '/api/auth' */\n basePath?: string;\n};\n\n/**\n * Provider wired to the server-side session.\n *\n * The plain `<LumoAuthProvider>` keeps tokens in web storage, which the server\n * cannot see — so a page always renders signed-out first and corrects itself\n * after hydration. This one reads the session from the httpOnly cookie via the\n * route handler, matching what `auth()` already rendered on the server.\n */\nexport function LumoAuthNextProvider({\n basePath = '/api/auth',\n children,\n ...rest\n}: LumoAuthNextProviderProps) {\n // Memoised: `storage` is a dependency of the provider's session useMemo, so\n // a new adapter each render would rebuild the session every render.\n const storage = useMemo(\n () =>\n cookieStorageAdapter({\n sessionEndpoint: `${basePath}/session`,\n logoutEndpoint: `${basePath}/logout`,\n }),\n [basePath],\n );\n\n return (\n <LumoAuthProvider {...rest} storage={storage}>\n {children}\n </LumoAuthProvider>\n );\n}\n"],"mappings":";;;;AAWA,SAAS,gBAAqC;AAG9C,SAAS,oBAAAA,yBAAwB;AAGjC,SAAS,QAAQ,QAAQ,oBAAoB;AAG7C,SAAS,YAAY,YAAY,mBAAmB;AAGpD,SAAS,eAAe;AAGxB,SAAS,UAAU,WAAW,wBAAwB;AAGtD,SAAS,cAAc,cAAc,qBAAqB;AAG1D;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;;;ACzCP,SAAS,eAAe;AACxB,SAAS,wBAAoD;AAC7D,SAAS,4BAA4B;AAgC7B;AAjBD,SAAS,qBAAqB;AAAA,EACjC,WAAW;AAAA,EACX;AAAA,EACA,GAAG;AACP,GAA8B;AAG1B,QAAM,UAAU;AAAA,IACZ,MACI,qBAAqB;AAAA,MACjB,iBAAiB,GAAG,QAAQ;AAAA,MAC5B,gBAAgB,GAAG,QAAQ;AAAA,IAC/B,CAAC;AAAA,IACL,CAAC,QAAQ;AAAA,EACb;AAEA,SACI,oBAAC,oBAAkB,GAAG,MAAM,SACvB,UACL;AAER;","names":["LumoAuthProvider"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/provider.tsx","../src/defaults.ts"],"sourcesContent":["'use client';\n\n// @lumoauth/nextjs — client entry.\n//\n// Re-exports the React SDK so a Next.js app needs one dependency. Everything\n// server-side (auth, currentUser, route handlers, middleware) lives in\n// @lumoauth/nextjs/server, which is never bundled for the browser.\n\n// Named re-exports, not `export *`: Next 14 rejects `export *` in a module\n// carrying the \"use client\" directive. Keep this list in sync with\n// @lumoauth/react's index.\nexport { LumoAuth, type LumoAuthConfig } from '@lumoauth/react';\n\n// Provider\nexport { LumoAuthProvider } from '@lumoauth/react';\n\n// Authentication Components\nexport { SignIn, SignUp, AuthCallback } from '@lumoauth/react';\n\n// User Components\nexport { UserButton, UserAvatar, UserProfile } from '@lumoauth/react';\n\n// Authorization Components\nexport { Protect } from '@lumoauth/react';\n\n// Control Components\nexport { SignedIn, SignedOut, RedirectToSignIn } from '@lumoauth/react';\n\n// Unstyled Components\nexport { SignInButton, SignUpButton, SignOutButton } from '@lumoauth/react';\n\n// Hooks\nexport {\n useAuth,\n useUser,\n useSignIn,\n useSession,\n useLumoAuth,\n usePermission,\n useZanzibar,\n useAbac,\n useMagicLink,\n useEmailFirst,\n} from '@lumoauth/react';\n\n// Types\nexport type {\n LumoAuthProviderProps,\n LumoAuthUser,\n AuthState,\n AuthStatus,\n LumoAuthContextValue,\n SignInProps,\n SignUpProps,\n UserButtonProps,\n UserAvatarProps,\n UserProfileProps,\n ProtectProps,\n AppearanceProps,\n AuthCallbackProps,\n SignedInProps,\n SignedOutProps,\n SignInButtonProps,\n SignUpButtonProps,\n SignOutButtonProps,\n RedirectToSignInProps,\n UseMagicLinkReturn,\n UseEmailFirstReturn,\n} from '@lumoauth/react';\n\nexport { LumoAuthNextProvider } from './provider';\n","'use client';\n\nimport { useMemo } from 'react';\nimport { LumoAuthProvider, type LumoAuthProviderProps } from '@lumoauth/react';\nimport { cookieStorageAdapter } from '@lumoauth/client';\nimport { DEFAULT_DOMAIN } from './defaults';\n\nexport type LumoAuthNextProviderProps = Omit<LumoAuthProviderProps, 'storage' | 'domain'> & {\n /**\n * Base URL of the LumoAuth region of the organization.\n * @default 'https://app.lumoauth.dev' (US). EU: 'https://eu.app.lumoauth.dev'.\n */\n domain?: string;\n /** Base path where createRouteHandler is mounted. @default '/api/auth' */\n basePath?: string;\n};\n\n/**\n * Provider wired to the server-side session.\n *\n * The plain `<LumoAuthProvider>` keeps tokens in web storage, which the server\n * cannot see — so a page always renders signed-out first and corrects itself\n * after hydration. This one reads the session from the httpOnly cookie via the\n * route handler, matching what `auth()` already rendered on the server.\n */\nexport function LumoAuthNextProvider({\n basePath = '/api/auth',\n domain,\n children,\n ...rest\n}: LumoAuthNextProviderProps) {\n // Memoised: `storage` is a dependency of the provider's session useMemo, so\n // a new adapter each render would rebuild the session every render.\n const storage = useMemo(\n () =>\n cookieStorageAdapter({\n sessionEndpoint: `${basePath}/session`,\n logoutEndpoint: `${basePath}/logout`,\n }),\n [basePath],\n );\n\n return (\n // `||`, not a parameter default: an unset NEXT_PUBLIC_ variable can\n // arrive as an empty string.\n <LumoAuthProvider {...rest} domain={domain || DEFAULT_DOMAIN} storage={storage}>\n {children}\n </LumoAuthProvider>\n );\n}\n","// Shared by the client and the server entry, so it must not import anything\n// server-only.\n\n/** US region. EU organizations set NEXT_PUBLIC_LUMOAUTH_DOMAIN=https://eu.app.lumoauth.dev. */\nexport const DEFAULT_DOMAIN = 'https://app.lumoauth.dev';\n\n/**\n * Where `createRouteHandler()` receives the authorization response. Fixed,\n * like the login path that the middleware and `protectPage()` redirect to,\n * so the URL to register is always `{app origin}/api/auth/callback`.\n */\nexport const CALLBACK_PATH = '/api/auth/callback';\n\n/** The login route of `createRouteHandler()`. */\nexport const LOGIN_PATH = '/api/auth/login';\n"],"mappings":";;;;AAWA,SAAS,gBAAqC;AAG9C,SAAS,oBAAAA,yBAAwB;AAGjC,SAAS,QAAQ,QAAQ,oBAAoB;AAG7C,SAAS,YAAY,YAAY,mBAAmB;AAGpD,SAAS,eAAe;AAGxB,SAAS,UAAU,WAAW,wBAAwB;AAGtD,SAAS,cAAc,cAAc,qBAAqB;AAG1D;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;;;ACzCP,SAAS,eAAe;AACxB,SAAS,wBAAoD;AAC7D,SAAS,4BAA4B;;;ACA9B,IAAM,iBAAiB;;;ADyCtB;AApBD,SAAS,qBAAqB;AAAA,EACjC,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EACA,GAAG;AACP,GAA8B;AAG1B,QAAM,UAAU;AAAA,IACZ,MACI,qBAAqB;AAAA,MACjB,iBAAiB,GAAG,QAAQ;AAAA,MAC5B,gBAAgB,GAAG,QAAQ;AAAA,IAC/B,CAAC;AAAA,IACL,CAAC,QAAQ;AAAA,EACb;AAEA;AAAA;AAAA;AAAA,IAGI,oBAAC,oBAAkB,GAAG,MAAM,QAAQ,UAAU,gBAAgB,SACzD,UACL;AAAA;AAER;","names":["LumoAuthProvider"]}
package/dist/server.d.mts CHANGED
@@ -2,7 +2,10 @@ import { UserInfo } from '@lumoauth/shared';
2
2
  import { NextRequest, NextResponse } from 'next/server';
3
3
 
4
4
  interface LumoAuthNextConfig {
5
- /** Base URL of your LumoAuth instance. */
5
+ /**
6
+ * Base URL of the LumoAuth region of the organization.
7
+ * @default 'https://app.lumoauth.dev' (US). EU: 'https://eu.app.lumoauth.dev'.
8
+ */
6
9
  domain: string;
7
10
  /** Organization slug. */
8
11
  orgId: string;
@@ -12,8 +15,17 @@ interface LumoAuthNextConfig {
12
15
  clientSecret?: string;
13
16
  /** Secret used to seal the session cookie. At least 32 characters. */
14
17
  secret: string;
15
- /** Absolute redirect URI registered with the OAuth client. */
16
- redirectUri: string;
18
+ /**
19
+ * Absolute redirect URI registered with the OAuth client.
20
+ *
21
+ * Optional. By default each sign-in uses `{origin}/api/auth/callback`,
22
+ * where `{origin}` is the public address of the request (the
23
+ * `X-Forwarded-Host` / `Host` header), so the same build works on
24
+ * localhost, on preview deployments and in production. Set it only to pin
25
+ * the app to one address; its origin then also becomes the origin of
26
+ * every redirect back to the app.
27
+ */
28
+ redirectUri?: string;
17
29
  /** Where to send a signed-out user. @default '/' */
18
30
  afterSignOutUrl?: string;
19
31
  /** Where to send a freshly signed-in user. @default '/' */
@@ -30,6 +42,9 @@ interface LumoAuthNextConfig {
30
42
  * both the client provider and the server. `LUMOAUTH_SECRET` and
31
43
  * `LUMOAUTH_CLIENT_SECRET` are deliberately NOT public — a `NEXT_PUBLIC_`
32
44
  * prefix would inline them into the browser bundle.
45
+ *
46
+ * An empty variable counts as unset: hosting dashboards and app builders
47
+ * often create a variable with an empty value.
33
48
  */
34
49
  declare function resolveConfig(overrides?: Partial<LumoAuthNextConfig>): LumoAuthNextConfig;
35
50
 
@@ -115,6 +130,11 @@ declare function protectPage(opts?: {
115
130
  * export const { GET, POST } = createRouteHandler();
116
131
  * ```
117
132
  *
133
+ * Register `{app origin}/api/auth/callback` as a redirect URI of the
134
+ * application, for every address the app runs on (localhost, previews,
135
+ * production). The handler builds that URL from each request, so no
136
+ * environment variable names it.
137
+ *
118
138
  * The server owns the whole OAuth exchange, so tokens live in an httpOnly
119
139
  * cookie and never reach JavaScript. That is what makes `auth()` work in a
120
140
  * server component — and therefore what makes a signed-in page render
package/dist/server.d.ts CHANGED
@@ -2,7 +2,10 @@ import { UserInfo } from '@lumoauth/shared';
2
2
  import { NextRequest, NextResponse } from 'next/server';
3
3
 
4
4
  interface LumoAuthNextConfig {
5
- /** Base URL of your LumoAuth instance. */
5
+ /**
6
+ * Base URL of the LumoAuth region of the organization.
7
+ * @default 'https://app.lumoauth.dev' (US). EU: 'https://eu.app.lumoauth.dev'.
8
+ */
6
9
  domain: string;
7
10
  /** Organization slug. */
8
11
  orgId: string;
@@ -12,8 +15,17 @@ interface LumoAuthNextConfig {
12
15
  clientSecret?: string;
13
16
  /** Secret used to seal the session cookie. At least 32 characters. */
14
17
  secret: string;
15
- /** Absolute redirect URI registered with the OAuth client. */
16
- redirectUri: string;
18
+ /**
19
+ * Absolute redirect URI registered with the OAuth client.
20
+ *
21
+ * Optional. By default each sign-in uses `{origin}/api/auth/callback`,
22
+ * where `{origin}` is the public address of the request (the
23
+ * `X-Forwarded-Host` / `Host` header), so the same build works on
24
+ * localhost, on preview deployments and in production. Set it only to pin
25
+ * the app to one address; its origin then also becomes the origin of
26
+ * every redirect back to the app.
27
+ */
28
+ redirectUri?: string;
17
29
  /** Where to send a signed-out user. @default '/' */
18
30
  afterSignOutUrl?: string;
19
31
  /** Where to send a freshly signed-in user. @default '/' */
@@ -30,6 +42,9 @@ interface LumoAuthNextConfig {
30
42
  * both the client provider and the server. `LUMOAUTH_SECRET` and
31
43
  * `LUMOAUTH_CLIENT_SECRET` are deliberately NOT public — a `NEXT_PUBLIC_`
32
44
  * prefix would inline them into the browser bundle.
45
+ *
46
+ * An empty variable counts as unset: hosting dashboards and app builders
47
+ * often create a variable with an empty value.
33
48
  */
34
49
  declare function resolveConfig(overrides?: Partial<LumoAuthNextConfig>): LumoAuthNextConfig;
35
50
 
@@ -115,6 +130,11 @@ declare function protectPage(opts?: {
115
130
  * export const { GET, POST } = createRouteHandler();
116
131
  * ```
117
132
  *
133
+ * Register `{app origin}/api/auth/callback` as a redirect URI of the
134
+ * application, for every address the app runs on (localhost, previews,
135
+ * production). The handler builds that URL from each request, so no
136
+ * environment variable names it.
137
+ *
118
138
  * The server owns the whole OAuth exchange, so tokens live in an httpOnly
119
139
  * cookie and never reach JavaScript. That is what makes `auth()` work in a
120
140
  * server component — and therefore what makes a signed-in page render