@payez/next-mvp 4.0.13 → 4.0.15
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/auth/better-auth.js
CHANGED
|
@@ -166,9 +166,9 @@ function createBetterAuthInstance(idpConfig) {
|
|
|
166
166
|
idpAccessTokenExpires: result.expires_in
|
|
167
167
|
? Date.now() + result.expires_in * 1000
|
|
168
168
|
: Date.now() + 15 * 60 * 1000,
|
|
169
|
-
userId: String(result.user?.
|
|
169
|
+
userId: String(result.user?.user_id || result.user?.id || result.user_id || userId),
|
|
170
170
|
email: result.user?.email || result.email || email,
|
|
171
|
-
name: result.user?.name || result.name || name,
|
|
171
|
+
name: result.user?.full_name || result.user?.name || result.name || name,
|
|
172
172
|
roles: result.user?.roles || result.roles || [],
|
|
173
173
|
};
|
|
174
174
|
await (0, redis_1.getRedis)().setex(baKey, 7 * 24 * 60 * 60, JSON.stringify(baData));
|
|
@@ -99,16 +99,30 @@ async function tryBetterAuthSession(requestCookies) {
|
|
|
99
99
|
if (!result?.session || !result?.user) {
|
|
100
100
|
return null;
|
|
101
101
|
}
|
|
102
|
-
//
|
|
102
|
+
// Read IDP tokens from BA Redis session (stored by post-login hook)
|
|
103
|
+
let idpTokens = null;
|
|
104
|
+
try {
|
|
105
|
+
const { getRedis } = await Promise.resolve().then(() => __importStar(require('../lib/redis')));
|
|
106
|
+
const { getAppSlug } = await Promise.resolve().then(() => __importStar(require('../lib/app-slug')));
|
|
107
|
+
const baKey = `ba:${getAppSlug()}:${result.session.token}`;
|
|
108
|
+
const baRaw = await getRedis().get(baKey);
|
|
109
|
+
if (baRaw) {
|
|
110
|
+
const baData = JSON.parse(baRaw);
|
|
111
|
+
idpTokens = baData.idpTokens;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch { /* Redis unavailable */ }
|
|
115
|
+
// Map Better Auth session + IDP tokens to SessionData
|
|
103
116
|
const sessionData = {
|
|
104
|
-
userId: result.user.id || '',
|
|
105
|
-
email: result.user.email || '',
|
|
106
|
-
name: result.user.name || undefined,
|
|
107
|
-
roles: [],
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
117
|
+
userId: idpTokens?.userId || result.user.id || '',
|
|
118
|
+
email: idpTokens?.email || result.user.email || '',
|
|
119
|
+
name: idpTokens?.name || result.user.name || undefined,
|
|
120
|
+
roles: idpTokens?.roles || [],
|
|
121
|
+
idpAccessToken: idpTokens?.idpAccessToken,
|
|
122
|
+
idpRefreshToken: idpTokens?.idpRefreshToken,
|
|
123
|
+
idpAccessTokenExpires: idpTokens?.idpAccessTokenExpires
|
|
124
|
+
|| (result.session.expiresAt ? new Date(result.session.expiresAt).getTime() : Date.now() + 24 * 60 * 60 * 1000),
|
|
125
|
+
mfaVerified: true,
|
|
112
126
|
oauthProvider: 'google',
|
|
113
127
|
};
|
|
114
128
|
const jwtPayload = {
|
package/package.json
CHANGED
package/src/auth/better-auth.ts
CHANGED
|
@@ -178,9 +178,9 @@ export function createBetterAuthInstance(idpConfig: IDPClientConfig) {
|
|
|
178
178
|
idpAccessTokenExpires: result.expires_in
|
|
179
179
|
? Date.now() + result.expires_in * 1000
|
|
180
180
|
: Date.now() + 15 * 60 * 1000,
|
|
181
|
-
userId: String(result.user?.
|
|
181
|
+
userId: String(result.user?.user_id || result.user?.id || result.user_id || userId),
|
|
182
182
|
email: result.user?.email || result.email || email,
|
|
183
|
-
name: result.user?.name || result.name || name,
|
|
183
|
+
name: result.user?.full_name || result.user?.name || result.name || name,
|
|
184
184
|
roles: result.user?.roles || result.roles || [],
|
|
185
185
|
};
|
|
186
186
|
await getRedis().setex(baKey, 7 * 24 * 60 * 60, JSON.stringify(baData));
|
|
@@ -75,16 +75,30 @@ async function tryBetterAuthSession(
|
|
|
75
75
|
return null;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
//
|
|
78
|
+
// Read IDP tokens from BA Redis session (stored by post-login hook)
|
|
79
|
+
let idpTokens: any = null;
|
|
80
|
+
try {
|
|
81
|
+
const { getRedis } = await import('../lib/redis');
|
|
82
|
+
const { getAppSlug } = await import('../lib/app-slug');
|
|
83
|
+
const baKey = `ba:${getAppSlug()}:${result.session.token}`;
|
|
84
|
+
const baRaw = await getRedis().get(baKey);
|
|
85
|
+
if (baRaw) {
|
|
86
|
+
const baData = JSON.parse(baRaw);
|
|
87
|
+
idpTokens = baData.idpTokens;
|
|
88
|
+
}
|
|
89
|
+
} catch { /* Redis unavailable */ }
|
|
90
|
+
|
|
91
|
+
// Map Better Auth session + IDP tokens to SessionData
|
|
79
92
|
const sessionData: SessionData = {
|
|
80
|
-
userId: result.user.id || '',
|
|
81
|
-
email: result.user.email || '',
|
|
82
|
-
name: result.user.name || undefined,
|
|
83
|
-
roles: [],
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
93
|
+
userId: idpTokens?.userId || result.user.id || '',
|
|
94
|
+
email: idpTokens?.email || result.user.email || '',
|
|
95
|
+
name: idpTokens?.name || result.user.name || undefined,
|
|
96
|
+
roles: idpTokens?.roles || [],
|
|
97
|
+
idpAccessToken: idpTokens?.idpAccessToken,
|
|
98
|
+
idpRefreshToken: idpTokens?.idpRefreshToken,
|
|
99
|
+
idpAccessTokenExpires: idpTokens?.idpAccessTokenExpires
|
|
100
|
+
|| (result.session.expiresAt ? new Date(result.session.expiresAt).getTime() : Date.now() + 24 * 60 * 60 * 1000),
|
|
101
|
+
mfaVerified: true,
|
|
88
102
|
oauthProvider: 'google',
|
|
89
103
|
};
|
|
90
104
|
|