@payez/next-mvp 4.0.40 → 4.0.41
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,11 +69,9 @@ async function getTokenTestAware(req) {
|
|
|
69
69
|
return null;
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
// Production path:
|
|
72
|
+
// Production path: Better Auth session
|
|
73
73
|
const session = await (0, auth_1.getSession)(req);
|
|
74
74
|
if (session?.user && session?.session?.token) {
|
|
75
|
-
// Return a token-like object for backward compatibility with callers
|
|
76
|
-
// that access token.sub, token.email, token.sessionToken, token.roles, etc.
|
|
77
75
|
return {
|
|
78
76
|
sub: session.user.id,
|
|
79
77
|
email: session.user.email,
|
|
@@ -83,51 +81,5 @@ async function getTokenTestAware(req) {
|
|
|
83
81
|
...session.user,
|
|
84
82
|
};
|
|
85
83
|
}
|
|
86
|
-
// Fallback: NextAuth JWT cookie (for sites still on NextAuth like localhost.api.payez.net)
|
|
87
|
-
// Use eval'd require to bypass bundler analysis entirely
|
|
88
|
-
try {
|
|
89
|
-
let nextAuthJwt = null;
|
|
90
|
-
try {
|
|
91
|
-
// eslint-disable-next-line @typescript-eslint/no-implied-eval, no-eval
|
|
92
|
-
const dynamicRequire = eval('require');
|
|
93
|
-
nextAuthJwt = dynamicRequire('next-auth/jwt');
|
|
94
|
-
}
|
|
95
|
-
catch {
|
|
96
|
-
logger_1.logger.debug('[GET_TOKEN] next-auth/jwt not installed in consumer');
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
if (nextAuthJwt?.getToken) {
|
|
100
|
-
const { resolveNextAuthSecret } = await Promise.resolve().then(() => __importStar(require('./nextauth-secret')));
|
|
101
|
-
const secret = await resolveNextAuthSecret();
|
|
102
|
-
const cookieName = (0, app_slug_1.getSessionCookieName)();
|
|
103
|
-
logger_1.logger.info('[GET_TOKEN] Trying NextAuth fallback', { cookieName });
|
|
104
|
-
const nextAuthToken = await nextAuthJwt.getToken({
|
|
105
|
-
req,
|
|
106
|
-
secret,
|
|
107
|
-
cookieName,
|
|
108
|
-
secureCookie: false,
|
|
109
|
-
});
|
|
110
|
-
if (nextAuthToken) {
|
|
111
|
-
logger_1.logger.info('[GET_TOKEN] Resolved via NextAuth JWT fallback');
|
|
112
|
-
return nextAuthToken;
|
|
113
|
-
}
|
|
114
|
-
const { getSecureSessionCookieName } = await Promise.resolve().then(() => __importStar(require('./app-slug')));
|
|
115
|
-
const secureCookieName = getSecureSessionCookieName();
|
|
116
|
-
const secureToken = await nextAuthJwt.getToken({
|
|
117
|
-
req,
|
|
118
|
-
secret,
|
|
119
|
-
cookieName: secureCookieName,
|
|
120
|
-
secureCookie: true,
|
|
121
|
-
});
|
|
122
|
-
if (secureToken) {
|
|
123
|
-
logger_1.logger.info('[GET_TOKEN] Resolved via NextAuth JWT fallback (secure)');
|
|
124
|
-
return secureToken;
|
|
125
|
-
}
|
|
126
|
-
logger_1.logger.warn('[GET_TOKEN] NextAuth getToken returned null for both cookie names', { cookieName, secureCookieName });
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
catch (error) {
|
|
130
|
-
logger_1.logger.warn('[GET_TOKEN] NextAuth fallback failed', { error: error instanceof Error ? error.message : String(error) });
|
|
131
|
-
}
|
|
132
84
|
return null;
|
|
133
85
|
}
|
package/package.json
CHANGED
|
@@ -24,11 +24,9 @@ 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: Better Auth session
|
|
28
28
|
const session = await getSession(req);
|
|
29
29
|
if (session?.user && session?.session?.token) {
|
|
30
|
-
// Return a token-like object for backward compatibility with callers
|
|
31
|
-
// that access token.sub, token.email, token.sessionToken, token.roles, etc.
|
|
32
30
|
return {
|
|
33
31
|
sub: session.user.id,
|
|
34
32
|
email: session.user.email,
|
|
@@ -39,50 +37,5 @@ export async function getTokenTestAware(req: NextRequest): Promise<any> {
|
|
|
39
37
|
};
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
// Fallback: NextAuth JWT cookie (for sites still on NextAuth like localhost.api.payez.net)
|
|
43
|
-
// Use eval'd require to bypass bundler analysis entirely
|
|
44
|
-
try {
|
|
45
|
-
let nextAuthJwt: any = null;
|
|
46
|
-
try {
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/no-implied-eval, no-eval
|
|
48
|
-
const dynamicRequire = eval('require') as NodeRequire;
|
|
49
|
-
nextAuthJwt = dynamicRequire('next-auth/jwt');
|
|
50
|
-
} catch {
|
|
51
|
-
logger.debug('[GET_TOKEN] next-auth/jwt not installed in consumer');
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
if (nextAuthJwt?.getToken) {
|
|
55
|
-
const { resolveNextAuthSecret } = await import('./nextauth-secret');
|
|
56
|
-
const secret = await resolveNextAuthSecret();
|
|
57
|
-
const cookieName = getSessionCookieName();
|
|
58
|
-
logger.info('[GET_TOKEN] Trying NextAuth fallback', { cookieName });
|
|
59
|
-
const nextAuthToken = await nextAuthJwt.getToken({
|
|
60
|
-
req,
|
|
61
|
-
secret,
|
|
62
|
-
cookieName,
|
|
63
|
-
secureCookie: false,
|
|
64
|
-
});
|
|
65
|
-
if (nextAuthToken) {
|
|
66
|
-
logger.info('[GET_TOKEN] Resolved via NextAuth JWT fallback');
|
|
67
|
-
return nextAuthToken;
|
|
68
|
-
}
|
|
69
|
-
const { getSecureSessionCookieName } = await import('./app-slug');
|
|
70
|
-
const secureCookieName = getSecureSessionCookieName();
|
|
71
|
-
const secureToken = await nextAuthJwt.getToken({
|
|
72
|
-
req,
|
|
73
|
-
secret,
|
|
74
|
-
cookieName: secureCookieName,
|
|
75
|
-
secureCookie: true,
|
|
76
|
-
});
|
|
77
|
-
if (secureToken) {
|
|
78
|
-
logger.info('[GET_TOKEN] Resolved via NextAuth JWT fallback (secure)');
|
|
79
|
-
return secureToken;
|
|
80
|
-
}
|
|
81
|
-
logger.warn('[GET_TOKEN] NextAuth getToken returned null for both cookie names', { cookieName, secureCookieName });
|
|
82
|
-
}
|
|
83
|
-
} catch (error) {
|
|
84
|
-
logger.warn('[GET_TOKEN] NextAuth fallback failed', { error: error instanceof Error ? error.message : String(error) });
|
|
85
|
-
}
|
|
86
|
-
|
|
87
40
|
return null;
|
|
88
41
|
}
|