@payez/next-mvp 4.1.10 → 4.1.12
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/dist/api-handlers/auth/refresh.js +15 -38
- package/dist/auth/better-auth.js +9 -18
- package/dist/client/better-auth-client.d.ts +14 -2
- package/dist/lib/ensure-fresh-access-token.js +7 -30
- package/dist/lib/session-store.d.ts +0 -1
- package/dist/lib/session-store.js +29 -33
- package/dist/lib/startup-init.js +19 -19
- package/package.json +4 -3
- package/scripts/check-internal-url-usage.sh +73 -73
- package/src/api/index.ts +17 -17
- package/src/api-handlers/account/masked-info.ts +45 -45
- package/src/api-handlers/account/profile.ts +80 -80
- package/src/api-handlers/account/recovery/initiate.ts +23 -23
- package/src/api-handlers/account/recovery/send-code.ts +25 -25
- package/src/api-handlers/account/recovery/verify-code.ts +25 -25
- package/src/api-handlers/account/reset-password.ts +23 -23
- package/src/api-handlers/account/send-code.ts +76 -76
- package/src/api-handlers/account/validate-password.ts +118 -118
- package/src/api-handlers/admin/stats.ts +249 -249
- package/src/api-handlers/anon/preferences.ts +123 -123
- package/src/api-handlers/auth/jwks.ts +20 -20
- package/src/api-handlers/auth/login.ts +240 -240
- package/src/api-handlers/auth/refresh.ts +15 -38
- package/src/api-handlers/auth/validate.ts +43 -43
- package/src/api-handlers/session/viability.ts +142 -142
- package/src/auth/better-auth.ts +9 -14
- package/src/auth/unauthenticated-routes.ts +2 -2
- package/src/client/better-auth-client.ts +70 -70
- package/src/client/fetchWithSession.ts +21 -21
- package/src/client/index.ts +13 -13
- package/src/client/useAnonSession.ts +131 -131
- package/src/components/admin/VibeAdminContext.tsx +87 -87
- package/src/config/logging-config.ts +82 -82
- package/src/config/unauthenticated-routes.ts +19 -19
- package/src/edge/internal-api-url.ts +65 -65
- package/src/edge/middleware.ts +42 -42
- package/src/hooks/useProfile.ts +75 -75
- package/src/lib/anon-session.ts +213 -213
- package/src/lib/auth-secret.ts +137 -137
- package/src/lib/demo-mode.ts +17 -17
- package/src/lib/ensure-fresh-access-token.ts +7 -30
- package/src/lib/idp-client-config.ts +559 -559
- package/src/lib/idp-fetch.ts +126 -126
- package/src/lib/internal-api.ts +171 -171
- package/src/lib/jwt-decode-client.ts +45 -45
- package/src/lib/rate-limit-service.ts +9 -9
- package/src/lib/redis.ts +26 -26
- package/src/lib/refresh-token-validator.ts +64 -64
- package/src/lib/secret-validation.ts +8 -8
- package/src/lib/session-store.ts +692 -695
- package/src/lib/session.ts +34 -34
- package/src/lib/startup-init.ts +251 -251
- package/src/lib/token-expiry.ts +40 -40
- package/src/lib/token-lifecycle.ts +470 -470
- package/src/lib/types/api-responses.ts +336 -336
- package/src/middleware/auth-decision.ts +43 -43
- package/src/models/DecodedAccessToken.ts +16 -16
- package/src/models/SessionModel.ts +264 -264
- package/src/pages/admin-roles/index.ts +9 -9
- package/src/pages/security/EnhancedSecurityPage.tsx +9 -9
- package/src/routes/account/index.ts +31 -31
- package/src/routes/account/masked-info.ts +36 -36
- package/src/routes/account/send-code.ts +39 -39
- package/src/routes/account/verify-email.ts +40 -40
- package/src/routes/account/verify-sms.ts +40 -40
- package/src/routes/auth/index.ts +22 -22
- package/src/routes/auth/refresh.ts +48 -48
- package/src/routes/auth/session.ts +166 -166
- package/src/routes/index.ts +17 -17
- package/src/routes/session/index.ts +7 -7
- package/src/routes/session/refresh-viability.ts +17 -17
- package/src/server/auth.ts +373 -373
- package/src/server/decode-session.ts +202 -202
- package/src/services/signalrActivityService.ts +258 -258
- package/src/theme/ThemeProvider.tsx +39 -39
- package/src/theme/default.ts +33 -33
- package/src/theme/index.ts +31 -31
- package/src/theme/types.ts +69 -69
- package/src/theme/useTheme.ts +57 -57
- package/src/theme/utils.ts +40 -40
- package/src/types/api.ts +12 -12
- package/src/types/auth.d.ts +23 -23
- package/src/types/auth.ts +22 -22
- package/src/types/logging.ts +11 -11
- package/src/types/recovery.ts +54 -54
- package/src/utils/api.ts +353 -353
- package/src/utils/circuitBreaker.ts +40 -40
- package/src/utils/error-message.ts +108 -108
- package/src/utils/layout/reservedSpace.ts +124 -124
|
@@ -1,118 +1,118 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
|
|
3
|
-
interface ValidatePasswordRequest {
|
|
4
|
-
password: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
interface ValidatePasswordResponse {
|
|
8
|
-
is_valid: boolean;
|
|
9
|
-
score: number;
|
|
10
|
-
failed_requirements: string[];
|
|
11
|
-
tip?: string;
|
|
12
|
-
policy?: {
|
|
13
|
-
min_length?: number;
|
|
14
|
-
require_uppercase?: boolean;
|
|
15
|
-
require_lowercase?: boolean;
|
|
16
|
-
require_digit?: boolean;
|
|
17
|
-
require_special?: boolean;
|
|
18
|
-
min_strength_score?: number;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export async function POST(req: NextRequest) {
|
|
23
|
-
try {
|
|
24
|
-
const body = await req.json();
|
|
25
|
-
const { password } = body as ValidatePasswordRequest;
|
|
26
|
-
const requestId = req.headers.get('x-request-id') ?? crypto.randomUUID();
|
|
27
|
-
|
|
28
|
-
// Validate input
|
|
29
|
-
if (!password || typeof password !== 'string') {
|
|
30
|
-
return NextResponse.json(
|
|
31
|
-
{
|
|
32
|
-
is_valid: false,
|
|
33
|
-
score: 0,
|
|
34
|
-
failed_requirements: ['Password is required'],
|
|
35
|
-
} as ValidatePasswordResponse,
|
|
36
|
-
{
|
|
37
|
-
status: 200, // Return 200 even for validation errors to keep UI responsive
|
|
38
|
-
headers: { 'Cache-Control': 'no-store' },
|
|
39
|
-
}
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Get IDP base URL and client ID from environment
|
|
44
|
-
const idpBaseUrl = process.env.IDP_URL;
|
|
45
|
-
|
|
46
|
-
const clientId = process.env.CLIENT_ID || process.env.NEXT_PUBLIC_CLIENT_ID;
|
|
47
|
-
|
|
48
|
-
if (!idpBaseUrl) {
|
|
49
|
-
console.error('[VALIDATE_PASSWORD] IDP_URL not configured');
|
|
50
|
-
return NextResponse.json(
|
|
51
|
-
{
|
|
52
|
-
is_valid: false,
|
|
53
|
-
score: 0,
|
|
54
|
-
failed_requirements: ['Password validation service unavailable'],
|
|
55
|
-
} as ValidatePasswordResponse,
|
|
56
|
-
{
|
|
57
|
-
status: 200,
|
|
58
|
-
headers: { 'Cache-Control': 'no-store' },
|
|
59
|
-
}
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Proxy request to IDP
|
|
64
|
-
const idpUrl = `${idpBaseUrl}/api/Account/validate-password`;
|
|
65
|
-
const payload = {
|
|
66
|
-
password,
|
|
67
|
-
client_id: clientId,
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const idpResponse = await fetch(idpUrl, {
|
|
71
|
-
method: 'POST',
|
|
72
|
-
headers: {
|
|
73
|
-
'Content-Type': 'application/json',
|
|
74
|
-
'x-request-id': requestId,
|
|
75
|
-
},
|
|
76
|
-
body: JSON.stringify(payload),
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const responseData = await idpResponse.json().catch(() => ({}));
|
|
80
|
-
|
|
81
|
-
if (!idpResponse.ok) {
|
|
82
|
-
console.error('[VALIDATE_PASSWORD] IDP error:', {
|
|
83
|
-
status: idpResponse.status,
|
|
84
|
-
response: responseData,
|
|
85
|
-
});
|
|
86
|
-
return NextResponse.json(
|
|
87
|
-
{
|
|
88
|
-
is_valid: false,
|
|
89
|
-
score: 0,
|
|
90
|
-
failed_requirements: ['Password validation failed'],
|
|
91
|
-
} as ValidatePasswordResponse,
|
|
92
|
-
{
|
|
93
|
-
status: 200,
|
|
94
|
-
headers: { 'Cache-Control': 'no-store' },
|
|
95
|
-
}
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Return the IDP response with proper structure
|
|
100
|
-
return NextResponse.json(responseData as ValidatePasswordResponse, {
|
|
101
|
-
status: 200,
|
|
102
|
-
headers: { 'Cache-Control': 'no-store' },
|
|
103
|
-
});
|
|
104
|
-
} catch (error) {
|
|
105
|
-
console.error('[VALIDATE_PASSWORD] Error:', error);
|
|
106
|
-
return NextResponse.json(
|
|
107
|
-
{
|
|
108
|
-
is_valid: false,
|
|
109
|
-
score: 0,
|
|
110
|
-
failed_requirements: ['Password validation failed'],
|
|
111
|
-
} as ValidatePasswordResponse,
|
|
112
|
-
{
|
|
113
|
-
status: 200,
|
|
114
|
-
headers: { 'Cache-Control': 'no-store' },
|
|
115
|
-
}
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
|
|
3
|
+
interface ValidatePasswordRequest {
|
|
4
|
+
password: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface ValidatePasswordResponse {
|
|
8
|
+
is_valid: boolean;
|
|
9
|
+
score: number;
|
|
10
|
+
failed_requirements: string[];
|
|
11
|
+
tip?: string;
|
|
12
|
+
policy?: {
|
|
13
|
+
min_length?: number;
|
|
14
|
+
require_uppercase?: boolean;
|
|
15
|
+
require_lowercase?: boolean;
|
|
16
|
+
require_digit?: boolean;
|
|
17
|
+
require_special?: boolean;
|
|
18
|
+
min_strength_score?: number;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function POST(req: NextRequest) {
|
|
23
|
+
try {
|
|
24
|
+
const body = await req.json();
|
|
25
|
+
const { password } = body as ValidatePasswordRequest;
|
|
26
|
+
const requestId = req.headers.get('x-request-id') ?? crypto.randomUUID();
|
|
27
|
+
|
|
28
|
+
// Validate input
|
|
29
|
+
if (!password || typeof password !== 'string') {
|
|
30
|
+
return NextResponse.json(
|
|
31
|
+
{
|
|
32
|
+
is_valid: false,
|
|
33
|
+
score: 0,
|
|
34
|
+
failed_requirements: ['Password is required'],
|
|
35
|
+
} as ValidatePasswordResponse,
|
|
36
|
+
{
|
|
37
|
+
status: 200, // Return 200 even for validation errors to keep UI responsive
|
|
38
|
+
headers: { 'Cache-Control': 'no-store' },
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Get IDP base URL and client ID from environment
|
|
44
|
+
const idpBaseUrl = process.env.IDP_URL;
|
|
45
|
+
|
|
46
|
+
const clientId = process.env.CLIENT_ID || process.env.NEXT_PUBLIC_CLIENT_ID;
|
|
47
|
+
|
|
48
|
+
if (!idpBaseUrl) {
|
|
49
|
+
console.error('[VALIDATE_PASSWORD] IDP_URL not configured');
|
|
50
|
+
return NextResponse.json(
|
|
51
|
+
{
|
|
52
|
+
is_valid: false,
|
|
53
|
+
score: 0,
|
|
54
|
+
failed_requirements: ['Password validation service unavailable'],
|
|
55
|
+
} as ValidatePasswordResponse,
|
|
56
|
+
{
|
|
57
|
+
status: 200,
|
|
58
|
+
headers: { 'Cache-Control': 'no-store' },
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Proxy request to IDP
|
|
64
|
+
const idpUrl = `${idpBaseUrl}/api/Account/validate-password`;
|
|
65
|
+
const payload = {
|
|
66
|
+
password,
|
|
67
|
+
client_id: clientId,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const idpResponse = await fetch(idpUrl, {
|
|
71
|
+
method: 'POST',
|
|
72
|
+
headers: {
|
|
73
|
+
'Content-Type': 'application/json',
|
|
74
|
+
'x-request-id': requestId,
|
|
75
|
+
},
|
|
76
|
+
body: JSON.stringify(payload),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const responseData = await idpResponse.json().catch(() => ({}));
|
|
80
|
+
|
|
81
|
+
if (!idpResponse.ok) {
|
|
82
|
+
console.error('[VALIDATE_PASSWORD] IDP error:', {
|
|
83
|
+
status: idpResponse.status,
|
|
84
|
+
response: responseData,
|
|
85
|
+
});
|
|
86
|
+
return NextResponse.json(
|
|
87
|
+
{
|
|
88
|
+
is_valid: false,
|
|
89
|
+
score: 0,
|
|
90
|
+
failed_requirements: ['Password validation failed'],
|
|
91
|
+
} as ValidatePasswordResponse,
|
|
92
|
+
{
|
|
93
|
+
status: 200,
|
|
94
|
+
headers: { 'Cache-Control': 'no-store' },
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Return the IDP response with proper structure
|
|
100
|
+
return NextResponse.json(responseData as ValidatePasswordResponse, {
|
|
101
|
+
status: 200,
|
|
102
|
+
headers: { 'Cache-Control': 'no-store' },
|
|
103
|
+
});
|
|
104
|
+
} catch (error) {
|
|
105
|
+
console.error('[VALIDATE_PASSWORD] Error:', error);
|
|
106
|
+
return NextResponse.json(
|
|
107
|
+
{
|
|
108
|
+
is_valid: false,
|
|
109
|
+
score: 0,
|
|
110
|
+
failed_requirements: ['Password validation failed'],
|
|
111
|
+
} as ValidatePasswordResponse,
|
|
112
|
+
{
|
|
113
|
+
status: 200,
|
|
114
|
+
headers: { 'Cache-Control': 'no-store' },
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}
|