@alore/auth-react-sdk 1.1.0-alpha.13 → 1.1.0-alpha.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/types.d.ts CHANGED
@@ -44,6 +44,12 @@ export interface AuthMachineContext {
44
44
  error?: string;
45
45
  active2fa?: TwoFactorAuth[];
46
46
  sessionId?: string;
47
+ socialChallenge?: {
48
+ sessionId: string;
49
+ idToken: string;
50
+ providerName: string;
51
+ device?: string;
52
+ };
47
53
  registerUser?: {
48
54
  email: string;
49
55
  nickname: string;
@@ -72,7 +78,10 @@ type SessionUser = {
72
78
  id: string;
73
79
  lastLogin: string | null;
74
80
  lastTransaction: string | null;
75
- nickname: string;
81
+ nickname: string | null;
82
+ /** Provider-hosted profile photo URL, when the account was created or
83
+ * linked through social login. Always https; null otherwise. */
84
+ picture: string | null;
76
85
  status: string;
77
86
  accessToken: string;
78
87
  refreshToken: string;
@@ -204,6 +204,39 @@ export declare class AloreAuth {
204
204
  type: 'INITIALIZE';
205
205
  forgeId?: string | null | undefined;
206
206
  }) => Promise<ForgeData>;
207
+ /**
208
+ * Passwordless social sign-in.
209
+ *
210
+ * Sends an OIDC id_token, not an access token: an access token carries no
211
+ * audience the backend can verify, so the older googleLogin flow below
212
+ * cannot tell a token minted for this app from one minted for any other.
213
+ * On success the backend returns a full session — there is no OTP and no
214
+ * password step.
215
+ */
216
+ socialLogin: (context: AuthMachineContext, event: {
217
+ type: 'SOCIAL_LOGIN';
218
+ payload: {
219
+ idToken: string;
220
+ providerName: string;
221
+ device?: string;
222
+ nonce?: string;
223
+ sessionId?: string;
224
+ emailCode?: string;
225
+ };
226
+ }) => Promise<{
227
+ emailChallenge: {
228
+ sessionId: any;
229
+ idToken: string;
230
+ providerName: string;
231
+ device: string | undefined;
232
+ };
233
+ sessionUser?: undefined;
234
+ isNewUser?: undefined;
235
+ } | {
236
+ sessionUser: any;
237
+ isNewUser: boolean;
238
+ emailChallenge?: undefined;
239
+ }>;
207
240
  googleLogin: (context: AuthMachineContext, event: {
208
241
  type: 'GOOGLE_LOGIN';
209
242
  payload: {
@@ -405,6 +405,62 @@ export class AloreAuth {
405
405
  yield this.throwParsedResponseError(response);
406
406
  return data;
407
407
  }),
408
+ /**
409
+ * Passwordless social sign-in.
410
+ *
411
+ * Sends an OIDC id_token, not an access token: an access token carries no
412
+ * audience the backend can verify, so the older googleLogin flow below
413
+ * cannot tell a token minted for this app from one minted for any other.
414
+ * On success the backend returns a full session — there is no OTP and no
415
+ * password step.
416
+ */
417
+ socialLogin: (context, event) => __awaiter(this, void 0, void 0, function* () {
418
+ const { idToken, providerName, device, nonce, sessionId, emailCode } = event.payload;
419
+ const { authProviderConfigs } = context;
420
+ const { firebaseCompatible, locale } = authProviderConfigs || {};
421
+ const query = new URLSearchParams();
422
+ if (firebaseCompatible)
423
+ query.set('firebaseCompatibleToken', String(firebaseCompatible));
424
+ if (locale)
425
+ query.set('locale', locale);
426
+ const queryString = query.toString();
427
+ const response = yield this.fetchWithProgressiveBackoff(`/auth/v1/social-login${queryString ? `?${queryString}` : ''}`, {
428
+ method: 'POST',
429
+ headers: {
430
+ 'Content-Type': 'application/json',
431
+ },
432
+ body: JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign({ idToken, provider: providerName }, (device ? { device } : {})), (nonce ? { nonce } : {})), (sessionId ? { sessionId } : {})), (emailCode ? { emailCode } : {}))),
433
+ });
434
+ // Not every 403 here is a refusal. Where the provider does not vouch for
435
+ // the address — Microsoft never does, since Entra carries no
436
+ // email_verified claim — the backend emails a code to the address the
437
+ // token claimed and hands back the session carrying it. The flow
438
+ // continues by calling this same endpoint again with that session and
439
+ // the code.
440
+ if (response.status === 403) {
441
+ const challenge = yield response
442
+ .clone()
443
+ .json()
444
+ .catch(() => null);
445
+ if ((challenge === null || challenge === void 0 ? void 0 : challenge.error) === 'SOCIAL_EMAIL_VERIFICATION_REQUIRED' && (challenge === null || challenge === void 0 ? void 0 : challenge.sessionId)) {
446
+ return {
447
+ emailChallenge: {
448
+ sessionId: challenge.sessionId,
449
+ idToken,
450
+ providerName,
451
+ device,
452
+ },
453
+ };
454
+ }
455
+ }
456
+ if (!response.ok)
457
+ yield this.throwParsedResponseError(response);
458
+ const sessionUser = yield response.json();
459
+ // 201 means the backend provisioned the account on this call. The
460
+ // consuming app keys its own user creation off that, so it has to survive
461
+ // as far as the onRegister/onLogin split in Auth.tsx.
462
+ return { sessionUser, isNewUser: response.status === 201 };
463
+ }),
408
464
  // Google login flow
409
465
  googleLogin: (context, event) => __awaiter(this, void 0, void 0, function* () {
410
466
  const { accessToken, providerName } = event.payload;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alore/auth-react-sdk",
3
- "version": "1.1.0-alpha.13",
3
+ "version": "1.1.0-alpha.15",
4
4
  "repository": "https://github.com/0xCarbon/alore-js",
5
5
  "description": "SDK for Alore Auth",
6
6
  "main": "dist/index.js",