@payez/next-mvp 4.0.36 → 4.0.37
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.
|
@@ -69,18 +69,38 @@ async function getTokenTestAware(req) {
|
|
|
69
69
|
return null;
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
// Production path:
|
|
72
|
+
// Production path: try Better Auth first, fall back to NextAuth JWT cookie
|
|
73
73
|
const session = await (0, auth_1.getSession)(req);
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
74
|
+
if (session) {
|
|
75
|
+
// Return a token-like object for backward compatibility with callers
|
|
76
|
+
// that access token.sub, token.email, token.sessionToken, token.roles, etc.
|
|
77
|
+
return {
|
|
78
|
+
sub: session.user?.id,
|
|
79
|
+
email: session.user?.email,
|
|
80
|
+
name: session.user?.name,
|
|
81
|
+
sessionToken: session.session?.token,
|
|
82
|
+
roles: session.user?.roles || [],
|
|
83
|
+
...(session.user || {}),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
// Fallback: NextAuth JWT cookie (for sites still on NextAuth like localhost.api.payez.net)
|
|
87
|
+
// Use string-literal import that bundlers won't statically resolve
|
|
88
|
+
try {
|
|
89
|
+
const moduleName = 'next-auth/jwt';
|
|
90
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
91
|
+
const nextAuthJwt = await Promise.resolve(`${moduleName}`).then(s => __importStar(require(s))).catch(() => null);
|
|
92
|
+
if (nextAuthJwt?.getToken) {
|
|
93
|
+
const { resolveNextAuthSecret } = await Promise.resolve().then(() => __importStar(require('./nextauth-secret')));
|
|
94
|
+
const secret = await resolveNextAuthSecret();
|
|
95
|
+
const nextAuthToken = await nextAuthJwt.getToken({ req, secret });
|
|
96
|
+
if (nextAuthToken) {
|
|
97
|
+
logger_1.logger.debug('[GET_TOKEN] Resolved via NextAuth JWT fallback');
|
|
98
|
+
return nextAuthToken;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
logger_1.logger.debug('[GET_TOKEN] NextAuth fallback failed', { error: error instanceof Error ? error.message : String(error) });
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
86
106
|
}
|
package/package.json
CHANGED
|
@@ -24,17 +24,39 @@ export async function getTokenTestAware(req: NextRequest): Promise<any> {
|
|
|
24
24
|
return payload;
|
|
25
25
|
} catch (error) { logger.error('[GET_TOKEN] TEST_MODE token decode error:', { error: error instanceof Error ? error.message : String(error) }); return null; }
|
|
26
26
|
}
|
|
27
|
-
// Production path:
|
|
27
|
+
// Production path: try Better Auth first, fall back to NextAuth JWT cookie
|
|
28
28
|
const session = await getSession(req);
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
if (session) {
|
|
30
|
+
// Return a token-like object for backward compatibility with callers
|
|
31
|
+
// that access token.sub, token.email, token.sessionToken, token.roles, etc.
|
|
32
|
+
return {
|
|
33
|
+
sub: session.user?.id,
|
|
34
|
+
email: session.user?.email,
|
|
35
|
+
name: session.user?.name,
|
|
36
|
+
sessionToken: session.session?.token,
|
|
37
|
+
roles: session.user?.roles || [],
|
|
38
|
+
...(session.user || {}),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Fallback: NextAuth JWT cookie (for sites still on NextAuth like localhost.api.payez.net)
|
|
43
|
+
// Use string-literal import that bundlers won't statically resolve
|
|
44
|
+
try {
|
|
45
|
+
const moduleName = 'next-auth/jwt';
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
+
const nextAuthJwt: any = await import(/* webpackIgnore: true */ moduleName).catch(() => null);
|
|
48
|
+
if (nextAuthJwt?.getToken) {
|
|
49
|
+
const { resolveNextAuthSecret } = await import('./nextauth-secret');
|
|
50
|
+
const secret = await resolveNextAuthSecret();
|
|
51
|
+
const nextAuthToken = await nextAuthJwt.getToken({ req, secret });
|
|
52
|
+
if (nextAuthToken) {
|
|
53
|
+
logger.debug('[GET_TOKEN] Resolved via NextAuth JWT fallback');
|
|
54
|
+
return nextAuthToken;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
} catch (error) {
|
|
58
|
+
logger.debug('[GET_TOKEN] NextAuth fallback failed', { error: error instanceof Error ? error.message : String(error) });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return null;
|
|
40
62
|
}
|