@@ -14,7 +14,6 @@ import { z } from 'zod';
1414
1515import koaGuard from '#src/middleware/koa-guard.js' ;
1616
17- import { EnvSet , getTenantEndpoint } from '../../env-set/index.js' ;
1817import {
1918 buildVerificationRecordByIdAndType ,
2019 insertVerificationRecord ,
@@ -251,6 +250,13 @@ export default function verificationRoutes<T extends UserRouter>(
251250 }
252251 ) ;
253252
253+ /**
254+ * WebAuthn registration (passkey binding)
255+ *
256+ * The rpId must be exactly the domain from which this API is accessed.
257+ * This keeps behavior aligned with the experience flow.
258+ *
259+ */
254260 router . post (
255261 `${ verificationApiPrefix } /web-authn/registration` ,
256262 koaGuard ( {
@@ -262,21 +268,16 @@ export default function verificationRoutes<T extends UserRouter>(
262268 status : [ 200 ] ,
263269 } ) ,
264270 async ( ctx , next ) => {
265- const { id : userId } = ctx . auth ;
266-
267- // If custom domain is enabled, use the custom domain as the RP ID.
268- // Otherwise, use the default tenant hostname as the RP ID.
269- // The background is that a passkey must be registered with a specific RP ID, which is a domain.
270- // In the future, we will support specifying the RP ID.
271- const domain = await queries . domains . findActiveDomain ( tenantContext . id ) ;
272- const rpId = domain
273- ? domain . domain
274- : getTenantEndpoint ( tenantContext . id , EnvSet . values ) . hostname ;
271+ const {
272+ auth : { id : userId } ,
273+ URL : { hostname } ,
274+ } = ctx ;
275275
276276 const webAuthnVerification = WebAuthnVerification . create ( libraries , queries , userId ) ;
277277
278- const registrationOptions =
279- await webAuthnVerification . generateWebAuthnRegistrationOptions ( rpId ) ;
278+ const registrationOptions = await webAuthnVerification . generateWebAuthnRegistrationOptions (
279+ hostname // RP ID: Use the domain of the current API request (custom domain supported)
280+ ) ;
280281
281282 const { expiresAt } = await insertVerificationRecord ( webAuthnVerification , queries , userId ) ;
282283
0 commit comments