MasterKale / SimpleWebAuthn

WebAuthn, Simplified. A collection of TypeScript-first libraries for simpler WebAuthn integration. Supports modern browsers, Node, Deno, and more.
https://simplewebauthn.dev
MIT License
1.62k stars 137 forks source link

TypeError: Cannot read properties of undefined (reading 'challenge') #628

Closed hovanhoa closed 1 month ago

hovanhoa commented 1 month ago

Describe the issue

Can not register with example

Reproduction Steps

  1. Clone this repository
  2. Move to example folder
  3. Install packages by npm install
  4. Run example by npm run start
  5. Click on "Register" button
  6. Return "TypeError: Cannot read properties of undefined (reading 'challenge')"

Expected behavior

Open the popup to choose the authentication options

Dependencies

phamhunglam commented 1 month ago

I think there's something wrong with the latest update of /browser, version 11. version 10 works fine for me.

hovanhoa commented 1 month ago

I think there's something wrong with the latest update of /browser, version 11. version 10 works fine for me.

Someone contacted me and told me they were having the same problem. I already checked some commits on the example folder but I can not find anything wrong. I think the min file (example/public/index.html at line 6) was changed. Can you clear the cache on the browser and clone this source code again to reproduce?

phamhunglam commented 1 month ago

I'm not using the example code, but based on line 6 of index.html, it calls the latest version of SimpleWebAuthn/browser. I think you should point to a specific version (in my case, version 10) and try again.

hovanhoa commented 1 month ago

Yeah, I changed to version 10 and It's worked. Thank you. Maybe I still have not closed this issue so the author can see and fix it on version 11

MasterKale commented 1 month ago

Ah, v11 broke the API for both startRegistration() and startAuthentication(). I forgot the @simplewebauthn/browser import uses a CDN without a version specifier so it makes sense the front end started pulling v11 without any refactoring to account for the API change.

I'll fix this later this week. Thanks for your patience ✌️

MasterKale commented 1 month ago

Reopening so I'll remember to fix this.

meAyushSharma commented 1 month ago

same for me, e.startRegistration broke on client-side since it use cdn version /* [@simplewebauthn/browser@11.0.0] */, is there a way to revert back to v10?

hovanhoa commented 1 month ago

same for me, e.startRegistration broke on client-side since it use cdn version /* [@simplewebauthn/browser@11.0.0] */, is there a way to revert back to v10?

<script src="https://unpkg.com/@simplewebauthn/browser@10.0.0/dist/bundle/index.umd.min.js"></script>

Replace this one in line 6 on index.html file. It's worked for me

jschlesser commented 1 month ago

A note for anyone who makes it here in the near term.

It's broken for using NPM to install packages as well. I just updated to 11.0.0 on both browser and server packages. I checked that those are the latest on the public NPM repo.

I restructured the results of my generateRegistrationOptions remote call to this:

const startRegOptions = {
    optionsJSON: generatedRegistrationOptions,
    useAutoRegister: false,
};

and then the call to startRegistration(startRegOptions) works fine. I assume that when the libs hit 11.0.1 this will go away and the generateRegistrationOptions will structure in the optionsJSON or the docs will change.

For now the temp restructuring above got me moving again in my dev environment.

MasterKale commented 1 month ago

The example server has been updated to use v11 for everything. I took it for a spin locally and everything seems to work fine now.

Part of this was pointing the browser to a specific version of @simplewebauthn/browser for me to update when I also bump the version of @simplewebauthn/server.