Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AUT-1266] Propagate errors in passkey methods #40

Merged
merged 2 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@authsignal/browser",
"version": "0.1.8",
"version": "0.2.0",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
Expand Down
40 changes: 16 additions & 24 deletions src/passkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,15 @@ export class Passkey {
async signUp({userName, token}: SignUpParams) {
const optionsResponse = await this.api.registrationOptions({userName, token});

try {
const registrationResponse = await startRegistration(optionsResponse.options);

const addAuthenticatorResponse = await this.api.addAuthenticator({
challengeId: optionsResponse.challengeId,
registrationCredential: registrationResponse,
token,
});

return addAuthenticatorResponse?.accessToken;
} catch (error) {
console.error(error);
}
const registrationResponse = await startRegistration(optionsResponse.options);

const addAuthenticatorResponse = await this.api.addAuthenticator({
challengeId: optionsResponse.challengeId,
registrationCredential: registrationResponse,
token,
});

return addAuthenticatorResponse?.accessToken;
}

async signIn(params?: {token: string}): Promise<string | undefined>;
Expand All @@ -46,18 +42,14 @@ export class Passkey {

const optionsResponse = await this.api.authenticationOptions({token: params?.token});

try {
const authenticationResponse = await startAuthentication(optionsResponse.options, params?.autofill);
const authenticationResponse = await startAuthentication(optionsResponse.options, params?.autofill);

const verifyResponse = await this.api.verify({
challengeId: optionsResponse.challengeId,
authenticationCredential: authenticationResponse,
token: params?.token,
});
const verifyResponse = await this.api.verify({
challengeId: optionsResponse.challengeId,
authenticationCredential: authenticationResponse,
token: params?.token,
});

return verifyResponse?.accessToken;
} catch (error) {
console.error(error);
}
return verifyResponse?.accessToken;
}
}