@payez/next-mvp 4.0.4 → 4.0.5

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
@@ -1,30 +1,40 @@
1
1
  # @payez/next-mvp
2
2
 
3
- PayEz IDP authentication package for Next.js 14/15 with pre-built UI components and complete authentication flow.
3
+ Drop-in authentication for Next.js. One package, zero secret management in production.
4
4
 
5
- ## Version History
5
+ ```bash
6
+ npm install @payez/next-mvp next-auth
7
+ ```
8
+
9
+ ## How Secrets Work
10
+
11
+ You never manage signing keys or OAuth credentials directly. The package resolves them automatically at startup based on your environment.
6
12
 
7
- ### v2.4.2 (2025-11-14)
8
- - **Fixed**: Redirect loop on token expiration - middleware now allows NextAuth JWT callback to refresh expired tokens instead of immediately redirecting to login, preventing infinite redirect loops when access tokens expire
13
+ | Environment | How it works | Secrets in your config? |
14
+ |-------------|-------------|------------------------|
15
+ | **Dev** | App calls IDP broker on your private network. One API key in `.env.local`. | One key (rotatable via CLI) |
16
+ | **Production** | App calls a cluster-internal endpoint. Network boundary = identity. | None |
17
+ | **Enterprise** | App uses an issued license key against your own or our IDP. | One key (rotatable via CLI) |
9
18
 
10
- ### v2.4.1 (2025-11-14)
11
- - **Fixed**: Stale cookie detection - viability API now properly detects when JWT exists but Redis session is missing, preventing access with expired sessions
12
- - **Fixed**: Token refresh field names - changed to PascalCase (`RefreshToken`, `AuthenticationMethods`, `AuthenticationLevel`, `TwoFactorMethod`) to match IDP requirements, resolving 400 errors during token refresh
19
+ **In production, there are no secrets to configure, rotate, or leak.** The app proves its identity by being inside the cluster.
20
+
21
+ In dev, you have one key. Rotate it anytime:
22
+
23
+ ```bash
24
+ npx @payez/cli secret rotate
25
+ ```
13
26
 
14
- ### v2.4.0
15
- - Auth-ready v2 handlers with pre-configured routes
16
- - Redis session management improvements
17
- - Token refresh optimizations
27
+ Full architecture: [SECRET-MANAGEMENT-ARCHITECTURE.md](../../docs/SECRET-MANAGEMENT-ARCHITECTURE.md)
18
28
 
19
29
  ## Features
20
30
 
21
- - 🔐 **Complete Authentication Flow** - Login, logout, session management, password recovery
22
- - 🎨 **Pre-built UI Components** - Ready-to-use login, recovery, and verify-code pages
23
- - 🔄 **Automatic Token Refresh** - Built-in refresh token handling
24
- - 🎭 **Themeable** - Customize branding, colors, and layout via ThemeProvider
25
- - 📱 **Responsive Design** - Mobile-first Tailwind CSS components
26
- - 🚀 **Next.js 14/15 Ready** - Works with App Router and React Server Components
27
- - 🔒 **Secure by Default** - JWT-based authentication with PayEz IDP
31
+ - **Zero-secret production deployment** no signing keys, no OAuth secrets in your env
32
+ - **Complete authentication flow** login, logout, session management, password recovery
33
+ - **Pre-built UI components** themed login, recovery, and verify-code pages
34
+ - **Automatic token refresh** — built-in refresh token handling with Redis session backing
35
+ - **Google OAuth + 2FA** pre-configured providers, MFA with email/SMS
36
+ - **Themeable** branding, colors, and layout via ThemeProvider
37
+ - **Next.js 14/15** App Router, React Server Components, middleware-ready
28
38
 
29
39
  ## Installation
30
40
 
@@ -39,6 +39,14 @@ export declare function createBetterAuthInstance(idpConfig: IDPClientConfig): im
39
39
  refreshCache: true;
40
40
  };
41
41
  };
42
+ advanced: {
43
+ cookiePrefix: string;
44
+ cookies: {
45
+ session_token: {
46
+ name: string;
47
+ };
48
+ };
49
+ };
42
50
  plugins: [{
43
51
  id: "next-cookies";
44
52
  hooks: {
@@ -19,6 +19,7 @@ const better_auth_1 = require("better-auth");
19
19
  const next_js_1 = require("better-auth/next-js");
20
20
  const next_js_2 = require("better-auth/next-js");
21
21
  const idp_client_config_1 = require("../lib/idp-client-config");
22
+ const app_slug_1 = require("../lib/app-slug");
22
23
  /**
23
24
  * Build Better Auth social providers from IDP config.
24
25
  */
@@ -43,6 +44,7 @@ function buildBetterAuthProviders(config) {
43
44
  * Call after getIDPClientConfig() resolves.
44
45
  */
45
46
  function createBetterAuthInstance(idpConfig) {
47
+ const appSlug = idpConfig.clientSlug || (0, app_slug_1.getAppSlug)();
46
48
  return (0, better_auth_1.betterAuth)({
47
49
  secret: idpConfig.nextAuthSecret,
48
50
  socialProviders: buildBetterAuthProviders(idpConfig),
@@ -63,6 +65,15 @@ function createBetterAuthInstance(idpConfig) {
63
65
  refreshCache: true,
64
66
  },
65
67
  },
68
+ // Cookie prefix must match slim-middleware expectations ({slug}.session-token)
69
+ advanced: {
70
+ cookiePrefix: appSlug,
71
+ cookies: {
72
+ session_token: {
73
+ name: `${appSlug}.session-token`,
74
+ },
75
+ },
76
+ },
66
77
  plugins: [
67
78
  (0, next_js_1.nextCookies)(),
68
79
  ],
@@ -22,6 +22,14 @@ export declare function getAuthInstance(): Promise<import("better-auth/types").A
22
22
  refreshCache: true;
23
23
  };
24
24
  };
25
+ advanced: {
26
+ cookiePrefix: string;
27
+ cookies: {
28
+ session_token: {
29
+ name: string;
30
+ };
31
+ };
32
+ };
25
33
  plugins: [{
26
34
  id: "next-cookies";
27
35
  hooks: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payez/next-mvp",
3
- "version": "4.0.4",
3
+ "version": "4.0.5",
4
4
  "sideEffects": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -861,6 +861,7 @@
861
861
  "dependencies": {
862
862
  "@azure/identity": "^4.0.1",
863
863
  "@azure/keyvault-secrets": "^4.7.0",
864
+ "@better-auth/memory-adapter": "^1.5.6",
864
865
  "@upstash/redis": "^1.35.6",
865
866
  "better-auth": "^1.5.6",
866
867
  "ioredis": "^5.3.2",
@@ -872,10 +873,13 @@
872
873
  "nanoid": "^5.0.7"
873
874
  },
874
875
  "devDependencies": {
876
+ "@microsoft/signalr": "^8.0.17",
877
+ "@tanstack/react-query": "^5.95.2",
875
878
  "@types/jsonwebtoken": "^9.0.6",
876
879
  "@types/jwk-to-pem": "^2.0.3",
877
880
  "@types/node": "^22.14.0",
878
881
  "@types/react": "^19.0.0",
882
+ "lucide-react": "^1.7.0",
879
883
  "next": "^16.1.5",
880
884
  "tsc-alias": "^1.8.16",
881
885
  "typescript": "^5.4.5",
@@ -15,6 +15,7 @@ import { nextCookies } from 'better-auth/next-js';
15
15
  import { toNextJsHandler } from 'better-auth/next-js';
16
16
  import type { IDPClientConfig } from '../lib/idp-client-config';
17
17
  import { getIDPClientConfig } from '../lib/idp-client-config';
18
+ import { getAppSlug } from '../lib/app-slug';
18
19
 
19
20
  /**
20
21
  * Better Auth social provider config shape.
@@ -53,6 +54,8 @@ export function buildBetterAuthProviders(
53
54
  * Call after getIDPClientConfig() resolves.
54
55
  */
55
56
  export function createBetterAuthInstance(idpConfig: IDPClientConfig) {
57
+ const appSlug = idpConfig.clientSlug || getAppSlug();
58
+
56
59
  return betterAuth({
57
60
  secret: idpConfig.nextAuthSecret as string,
58
61
 
@@ -77,6 +80,16 @@ export function createBetterAuthInstance(idpConfig: IDPClientConfig) {
77
80
  },
78
81
  },
79
82
 
83
+ // Cookie prefix must match slim-middleware expectations ({slug}.session-token)
84
+ advanced: {
85
+ cookiePrefix: appSlug,
86
+ cookies: {
87
+ session_token: {
88
+ name: `${appSlug}.session-token`,
89
+ },
90
+ },
91
+ },
92
+
80
93
  plugins: [
81
94
  nextCookies(),
82
95
  ],