@micha.bigler/ui-core-micha 1.2.3 → 1.2.5

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.
@@ -178,12 +178,14 @@ async function registerPasskeyStart({ passwordless = true } = {}) {
178
178
  params: passwordless ? { passwordless: true } : {},
179
179
  withCredentials: true,
180
180
  });
181
- const data = res.data || {};
182
- // allauth.headless: { creation_options: { publicKey: { ... } } }
183
- const creationOptionsJson = (data.creation_options && data.creation_options.publicKey) ||
184
- data.creation_options ||
185
- data;
186
- return creationOptionsJson;
181
+ const responseBody = res.data || {};
182
+ // Handle nested 'data' wrapper if present, otherwise use body directly
183
+ const payload = responseBody.data || responseBody;
184
+ // Extract the inner publicKey structure required by the browser API
185
+ const publicKeyJson = (payload.creation_options && payload.creation_options.publicKey) ||
186
+ payload.publicKey ||
187
+ payload;
188
+ return publicKeyJson;
187
189
  }
188
190
  async function registerPasskeyComplete(credentialJson, name = 'Passkey') {
189
191
  const res = await axios.post(`${HEADLESS_BASE}/account/authenticators/webauthn`, {
@@ -197,10 +199,12 @@ export async function registerPasskey(name = 'Passkey') {
197
199
  if (!hasJsonWebAuthn) {
198
200
  throw new Error('Passkey JSON helpers are not available in this browser.');
199
201
  }
200
- const creationOptionsJson = await registerPasskeyStart({ passwordless: true });
202
+ // Hier bekommst du bereits den inneren publicKey-Block mit challenge etc.
203
+ const publicKeyJson = await registerPasskeyStart({ passwordless: true });
201
204
  let credential;
202
205
  try {
203
- const publicKeyOptions = window.PublicKeyCredential.parseCreationOptionsFromJSON(creationOptionsJson);
206
+ // publicKeyJson hat challenge auf Top-Level
207
+ const publicKeyOptions = window.PublicKeyCredential.parseCreationOptionsFromJSON(publicKeyJson);
204
208
  credential = await navigator.credentials.create({
205
209
  publicKey: publicKeyOptions,
206
210
  });
@@ -223,11 +227,13 @@ export async function registerPasskey(name = 'Passkey') {
223
227
  async function loginWithPasskeyStart() {
224
228
  ensureWebAuthnSupport();
225
229
  const res = await axios.get(`${HEADLESS_BASE}/auth/webauthn/login`, { withCredentials: true });
226
- const data = res.data || {};
227
- // allauth.headless: { request_options: { publicKey: { ... } } }
228
- const requestOptionsJson = (data.request_options && data.request_options.publicKey) ||
229
- data.request_options ||
230
- data;
230
+ const responseBody = res.data || {};
231
+ // Handle nested 'data' wrapper if present
232
+ const payload = responseBody.data || responseBody;
233
+ // Extract request options for authentication
234
+ const requestOptionsJson = (payload.request_options && payload.request_options.publicKey) ||
235
+ payload.request_options ||
236
+ payload;
231
237
  return requestOptionsJson;
232
238
  }
233
239
  async function loginWithPasskeyComplete(credentialJson) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micha.bigler/ui-core-micha",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "private": false,
@@ -235,17 +235,21 @@ async function registerPasskeyStart({ passwordless = true } = {}) {
235
235
  },
236
236
  );
237
237
 
238
- const data = res.data || {};
238
+ const responseBody = res.data || {};
239
239
 
240
- // allauth.headless: { creation_options: { publicKey: { ... } } }
241
- const creationOptionsJson =
242
- (data.creation_options && data.creation_options.publicKey) ||
243
- data.creation_options ||
244
- data;
240
+ // Handle nested 'data' wrapper if present, otherwise use body directly
241
+ const payload = responseBody.data || responseBody;
245
242
 
246
- return creationOptionsJson;
243
+ // Extract the inner publicKey structure required by the browser API
244
+ const publicKeyJson =
245
+ (payload.creation_options && payload.creation_options.publicKey) ||
246
+ payload.publicKey ||
247
+ payload;
248
+
249
+ return publicKeyJson;
247
250
  }
248
251
 
252
+
249
253
  async function registerPasskeyComplete(credentialJson, name = 'Passkey') {
250
254
  const res = await axios.post(
251
255
  `${HEADLESS_BASE}/account/authenticators/webauthn`,
@@ -265,12 +269,14 @@ export async function registerPasskey(name = 'Passkey') {
265
269
  throw new Error('Passkey JSON helpers are not available in this browser.');
266
270
  }
267
271
 
268
- const creationOptionsJson = await registerPasskeyStart({ passwordless: true });
272
+ // Hier bekommst du bereits den inneren publicKey-Block mit challenge etc.
273
+ const publicKeyJson = await registerPasskeyStart({ passwordless: true });
269
274
 
270
275
  let credential;
271
276
  try {
277
+ // publicKeyJson hat challenge auf Top-Level
272
278
  const publicKeyOptions =
273
- window.PublicKeyCredential.parseCreationOptionsFromJSON(creationOptionsJson);
279
+ window.PublicKeyCredential.parseCreationOptionsFromJSON(publicKeyJson);
274
280
 
275
281
  credential = await navigator.credentials.create({
276
282
  publicKey: publicKeyOptions,
@@ -301,13 +307,16 @@ async function loginWithPasskeyStart() {
301
307
  { withCredentials: true },
302
308
  );
303
309
 
304
- const data = res.data || {};
310
+ const responseBody = res.data || {};
311
+
312
+ // Handle nested 'data' wrapper if present
313
+ const payload = responseBody.data || responseBody;
305
314
 
306
- // allauth.headless: { request_options: { publicKey: { ... } } }
315
+ // Extract request options for authentication
307
316
  const requestOptionsJson =
308
- (data.request_options && data.request_options.publicKey) ||
309
- data.request_options ||
310
- data;
317
+ (payload.request_options && payload.request_options.publicKey) ||
318
+ payload.request_options ||
319
+ payload;
311
320
 
312
321
  return requestOptionsJson;
313
322
  }