Skip to content

Commit 846ebc9

Browse files
committed
Add first version of conditional create
1 parent a13c64e commit 846ebc9

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

packages/web-core/src/services/WebAuthnService.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/// <reference types="user-agent-data-types" /> <- add this line
33
import type { ClientCapabilities } from '@corbado/types';
44
import type { CredentialRequestOptionsJSON } from '@corbado/webauthn-json';
5-
import { create, get } from '@corbado/webauthn-json';
5+
import { get } from '@corbado/webauthn-json';
66
import type { CredentialCreationOptionsJSON } from '@corbado/webauthn-json/src/webauthn-json/basic/json';
77
import FingerprintJS from '@fingerprintjs/fingerprintjs';
88
import { detectIncognito } from 'detectincognitojs';
@@ -39,10 +39,19 @@ export class WebAuthnService {
3939
async createPasskeyRaw(serializedChallenge: string): Promise<string> {
4040
const abortController = this.abortOngoingOperation();
4141
const challenge = JSON.parse(serializedChallenge);
42-
challenge.signal = abortController.signal;
4342
this.#abortController = abortController;
4443

45-
const signedChallenge = await create(challenge);
44+
console.log('createPasskeyRaw challenge', challenge);
45+
46+
const publicKey = PublicKeyCredential.parseCreationOptionsFromJSON(challenge.publicKey);
47+
console.log('createPasskeyRaw publicKey', publicKey);
48+
const credential = (await navigator.credentials.create({
49+
publicKey,
50+
signal: abortController.signal,
51+
mediation: challenge.mediation,
52+
} as any)) as PublicKeyCredential;
53+
const signedChallenge = credential.toJSON();
54+
4655
return JSON.stringify(signedChallenge);
4756
}
4857

playground/connect-next/app/(no-auth)/login/PasswordForm.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const PasswordForm = ({ onClick, initialUserProvidedIdentifier, initialEr
3535
name='email'
3636
type='email'
3737
placeholder='user@acme.com'
38-
autoComplete='email'
38+
autoComplete='username'
3939
required
4040
className='mt-1 block w-full appearance-none rounded-md border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-black focus:outline-none focus:ring-black sm:text-sm'
4141
value={username}
@@ -53,6 +53,7 @@ export const PasswordForm = ({ onClick, initialUserProvidedIdentifier, initialEr
5353
id='password'
5454
name='password'
5555
type='password'
56+
autoComplete='current-password'
5657
required
5758
className='mt-1 block w-full appearance-none rounded-md border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-black focus:outline-none focus:ring-black sm:text-sm'
5859
value={password}

playground/connect-next/app/(no-auth)/page.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function SignupPage() {
1414
const [password, setPassword] = useState('');
1515
const [message, setMessage] = useState('');
1616

17-
const handleSignup = async (e: FormEvent<HTMLButtonElement>) => {
17+
const handleSignup = async (e: FormEvent<HTMLFormElement>) => {
1818
e.preventDefault();
1919
const username = generateRandomString(10);
2020

@@ -58,7 +58,10 @@ export default function SignupPage() {
5858
<h3 className='text-xl font-semibold'>Sign Up</h3>
5959
<p className='text-sm text-gray-500'>Create an account with your email, phone and password</p>
6060
</div>
61-
<form className='flex flex-col space-y-4 bg-gray-50 px-4 py-8 sm:px-8'>
61+
<form
62+
className='flex flex-col space-y-4 bg-gray-50 px-4 py-8 sm:px-8'
63+
onSubmit={handleSignup}
64+
>
6265
<div>
6366
<label
6467
htmlFor='email'
@@ -71,7 +74,7 @@ export default function SignupPage() {
7174
name='email'
7275
type='email'
7376
placeholder='Email'
74-
autoComplete='email'
77+
autoComplete='username'
7578
required
7679
className='mt-1 block w-full appearance-none rounded-md border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-black focus:outline-none focus:ring-black sm:text-sm'
7780
value={email}
@@ -90,6 +93,7 @@ export default function SignupPage() {
9093
name='password'
9194
type='password'
9295
placeholder='Password'
96+
autoComplete='new-password'
9397
required
9498
className='mt-1 block w-full appearance-none rounded-md border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-black focus:outline-none focus:ring-black sm:text-sm'
9599
value={password}
@@ -118,7 +122,7 @@ export default function SignupPage() {
118122
</div>
119123
{message && <div className='text-center text-red-700'>{message}</div>}
120124
<Button
121-
onClick={handleSignup}
125+
type='submit'
122126
className='w-full'
123127
size='lg'
124128
>

0 commit comments

Comments
 (0)