@payez/next-mvp 4.0.45 → 4.0.46
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.
|
@@ -81,5 +81,54 @@ async function getTokenTestAware(req) {
|
|
|
81
81
|
...session.user,
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
+
// Fallback for legacy NextAuth-based sites: try next-auth/jwt with the
|
|
85
|
+
// app-slug-prefixed cookie name. Uses runtime require so consumers without
|
|
86
|
+
// next-auth installed are unaffected.
|
|
87
|
+
try {
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval, no-eval
|
|
89
|
+
const dynamicRequire = eval('require');
|
|
90
|
+
let nextAuthJwt = null;
|
|
91
|
+
try {
|
|
92
|
+
nextAuthJwt = dynamicRequire('next-auth/jwt');
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return null; // next-auth not installed → BA-only consumer
|
|
96
|
+
}
|
|
97
|
+
if (!nextAuthJwt?.getToken)
|
|
98
|
+
return null;
|
|
99
|
+
const { resolveNextAuthSecret } = await Promise.resolve().then(() => __importStar(require('./nextauth-secret')));
|
|
100
|
+
const secret = await resolveNextAuthSecret();
|
|
101
|
+
if (!secret)
|
|
102
|
+
return null;
|
|
103
|
+
const cookieName = (0, app_slug_1.getSessionCookieName)();
|
|
104
|
+
let nextAuthToken = await nextAuthJwt.getToken({
|
|
105
|
+
req,
|
|
106
|
+
secret,
|
|
107
|
+
cookieName,
|
|
108
|
+
secureCookie: false,
|
|
109
|
+
});
|
|
110
|
+
if (nextAuthToken) {
|
|
111
|
+
logger_1.logger.debug('[GET_TOKEN] Resolved via NextAuth JWT (cookieName=' + cookieName + ')');
|
|
112
|
+
return nextAuthToken;
|
|
113
|
+
}
|
|
114
|
+
// Try secure cookie variant for production
|
|
115
|
+
const { getSecureSessionCookieName } = await Promise.resolve().then(() => __importStar(require('./app-slug')));
|
|
116
|
+
const secureCookieName = getSecureSessionCookieName();
|
|
117
|
+
nextAuthToken = await nextAuthJwt.getToken({
|
|
118
|
+
req,
|
|
119
|
+
secret,
|
|
120
|
+
cookieName: secureCookieName,
|
|
121
|
+
secureCookie: true,
|
|
122
|
+
});
|
|
123
|
+
if (nextAuthToken) {
|
|
124
|
+
logger_1.logger.debug('[GET_TOKEN] Resolved via NextAuth JWT (secure cookie)');
|
|
125
|
+
return nextAuthToken;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
logger_1.logger.debug('[GET_TOKEN] NextAuth fallback error', {
|
|
130
|
+
error: error instanceof Error ? error.message : String(error),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
84
133
|
return null;
|
|
85
134
|
}
|
package/package.json
CHANGED
|
@@ -37,5 +37,54 @@ export async function getTokenTestAware(req: NextRequest): Promise<any> {
|
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
// Fallback for legacy NextAuth-based sites: try next-auth/jwt with the
|
|
41
|
+
// app-slug-prefixed cookie name. Uses runtime require so consumers without
|
|
42
|
+
// next-auth installed are unaffected.
|
|
43
|
+
try {
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval, no-eval
|
|
45
|
+
const dynamicRequire = eval('require') as NodeRequire;
|
|
46
|
+
let nextAuthJwt: any = null;
|
|
47
|
+
try {
|
|
48
|
+
nextAuthJwt = dynamicRequire('next-auth/jwt');
|
|
49
|
+
} catch {
|
|
50
|
+
return null; // next-auth not installed → BA-only consumer
|
|
51
|
+
}
|
|
52
|
+
if (!nextAuthJwt?.getToken) return null;
|
|
53
|
+
|
|
54
|
+
const { resolveNextAuthSecret } = await import('./nextauth-secret');
|
|
55
|
+
const secret = await resolveNextAuthSecret();
|
|
56
|
+
if (!secret) return null;
|
|
57
|
+
|
|
58
|
+
const cookieName = getSessionCookieName();
|
|
59
|
+
let nextAuthToken = await nextAuthJwt.getToken({
|
|
60
|
+
req,
|
|
61
|
+
secret,
|
|
62
|
+
cookieName,
|
|
63
|
+
secureCookie: false,
|
|
64
|
+
});
|
|
65
|
+
if (nextAuthToken) {
|
|
66
|
+
logger.debug('[GET_TOKEN] Resolved via NextAuth JWT (cookieName=' + cookieName + ')');
|
|
67
|
+
return nextAuthToken;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Try secure cookie variant for production
|
|
71
|
+
const { getSecureSessionCookieName } = await import('./app-slug');
|
|
72
|
+
const secureCookieName = getSecureSessionCookieName();
|
|
73
|
+
nextAuthToken = await nextAuthJwt.getToken({
|
|
74
|
+
req,
|
|
75
|
+
secret,
|
|
76
|
+
cookieName: secureCookieName,
|
|
77
|
+
secureCookie: true,
|
|
78
|
+
});
|
|
79
|
+
if (nextAuthToken) {
|
|
80
|
+
logger.debug('[GET_TOKEN] Resolved via NextAuth JWT (secure cookie)');
|
|
81
|
+
return nextAuthToken;
|
|
82
|
+
}
|
|
83
|
+
} catch (error) {
|
|
84
|
+
logger.debug('[GET_TOKEN] NextAuth fallback error', {
|
|
85
|
+
error: error instanceof Error ? error.message : String(error),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
40
89
|
return null;
|
|
41
90
|
}
|