@payez/next-mvp 4.1.0 → 4.1.2

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.
@@ -18,6 +18,9 @@ export interface BetterAuthSocialProvider {
18
18
  clientId: string;
19
19
  clientSecret: string;
20
20
  scope?: string[];
21
+ prompt?: string;
22
+ accessType?: 'offline' | 'online';
23
+ hd?: string;
21
24
  }
22
25
  /**
23
26
  * Build Better Auth social providers from IDP config.
@@ -69,10 +69,28 @@ function buildBetterAuthProviders(config) {
69
69
  if (!oauth.enabled)
70
70
  continue;
71
71
  const name = oauth.provider.toLowerCase();
72
+ const additionalParams = oauth.additionalParams ?? {};
73
+ const rawPrompt = additionalParams.prompt;
74
+ const rawAccessType = additionalParams.accessType ?? additionalParams.access_type;
75
+ const rawHostedDomain = additionalParams.hd;
76
+ // Ensure profile scope is present for Google so avatar image is returned
77
+ const scopes = oauth.scopes?.split(' ') || [];
78
+ if (name === 'google' && !scopes.includes('profile')) {
79
+ scopes.push('profile');
80
+ }
72
81
  providers[name] = {
73
82
  clientId: oauth.clientId,
74
83
  clientSecret: oauth.clientSecret,
75
- scope: oauth.scopes?.split(' '),
84
+ scope: scopes.length > 0 ? scopes : undefined,
85
+ // Google is overly eager to reuse the last account unless we
86
+ // explicitly ask for account selection on each social login.
87
+ prompt: typeof rawPrompt === 'string'
88
+ ? rawPrompt
89
+ : name === 'google'
90
+ ? 'select_account'
91
+ : undefined,
92
+ accessType: rawAccessType === 'online' ? 'online' : rawAccessType === 'offline' ? 'offline' : undefined,
93
+ hd: typeof rawHostedDomain === 'string' ? rawHostedDomain : undefined,
76
94
  };
77
95
  }
78
96
  return providers;
@@ -301,8 +319,11 @@ async function exchangeOAuthForIdpTokens(sessionToken, provider = 'google') {
301
319
  userId: String(result.user?.user_id || result.user?.id || result.user_id || baUserId),
302
320
  email: result.user?.email || result.email || email,
303
321
  name: result.user?.full_name || result.user?.name || result.name || name,
322
+ image: image,
304
323
  roles: result.user?.roles || result.roles || [],
305
324
  mfaVerified: !requiresTwoFactor,
325
+ idpClientId: result.client_id ? String(result.client_id) : undefined,
326
+ merchantId: result.merchant_id ? String(result.merchant_id) : undefined,
306
327
  };
307
328
  // Store in BA Redis session (for decodeSession)
308
329
  baData.idpTokens = idpTokenData;