Skip to content

How do we link a passkey to an existing user? Since there's only register and authenticate methods #272

@fayazara

Description

@fayazara

I see that we have defineWebAuthnRegisterEventHandler but this is always expecting a userName and when we want to just link an credential to a existing user, its not possible.

export default defineWebAuthnRegisterEventHandler({
  async onSuccess(event, { credential }) {
    const { user } = await requireUserSession(event);
    // we have the users email here
    return user;
  },
});

The above endpoint breaks - it throws

{
    "url": "/api/auth/link-passkey",
    "statusCode": 400,
    "statusMessage": "",
    "message": "Invalid request, missing userName or verify property",
    "stack": "<pre><span class=\"stack internal\">at createError (./node_modules/.pnpm/h3@1.13.0/node_modules/h3/dist/index.mjs:78:15)</span>\n<span class=\"stack internal\">at Object.handler (./node_modules/.pnpm/nuxt-auth-utils@0.5.2_@simplewebauthn+browser@11.0.0_@simplewebauthn+server@11.0.0_encoding@0_53tvg2bimanm6byvroxwbmjc6q/node_modules/nuxt-auth-utils/dist/runtime/server/lib/webauthn/register.js:20:13)</span>\n<span class=\"stack internal\">at process.processTicksAndRejections (node:internal/process/task_queues:105:5)</span>\n<span class=\"stack internal\">at async ./node_modules/.pnpm/h3@1.13.0/node_modules/h3/dist/index.mjs:1978:19</span>\n<span class=\"stack internal\">at async Object.callAsync (./node_modules/.pnpm/unctx@2.3.1_webpack-sources@3.2.3/node_modules/unctx/dist/index.mjs:72:16)</span>\n<span class=\"stack internal\">at async Object.callAsync (./node_modules/.pnpm/unctx@2.3.1_webpack-sources@3.2.3/node_modules/unctx/dist/index.mjs:72:16)</span>\n<span class=\"stack internal\">at async Server.toNodeHandle (./node_modules/.pnpm/h3@1.13.0/node_modules/h3/dist/index.mjs:2270:7)</span></pre>"
}

@Gerbuuun is this handled somewhere that I am missing in the docs or can we not do this currently?

I can contribute, just want to make sure if this is not implemented already

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions