Skip to content

Commit

Permalink
Refactor: Rename functions and Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yunochi committed Sep 20, 2024
1 parent d9d71a0 commit ddc98c3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 4 additions & 0 deletions packages/backend/src/core/WebAuthnService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ export class WebAuthnService {
return authenticationOptions;
}

/**
* Initiate Passkey Auth (Without specifying user)
* @returns authenticationOptions
*/
@bindThis
public async initiateSignInWithPasskeyAuthentication(context: string): Promise<PublicKeyCredentialRequestOptionsJSON> {
const relyingParty = await this.getRelyingParty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export class SigninWithPasskeyApiService {

const context = body.context;
if (!context || typeof context !== 'string') {
// If try Authentication without context
return error(400, {
id: '1658cc2e-4495-461f-aee4-d403cdf073c1',
});
Expand Down
17 changes: 8 additions & 9 deletions packages/frontend/src/components/MkSignin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<div v-if="totpLogin" class="2fa-signin" :class="{ securityKeys: user && user.securityKeys }">
<div v-if="user && user.securityKeys" class="twofa-group tap-group">
<p>{{ i18n.ts.useSecurityKey }}</p>
<MkButton v-if="!queryingKey" @click="queryKey">
<MkButton v-if="!queryingKey" @click="query2FaKey">
{{ i18n.ts.retry }}
</MkButton>
</div>
Expand All @@ -57,7 +57,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<p :class="$style.orMsg">{{ i18n.ts.or }}</p>
</div>
<div v-if="!totpLogin && usePasswordLessLogin" class="twofa-group tap-group">
<MkButton v-if="!queryingKey" type="submit" :disabled="signing" style="margin: auto auto;" rounded large primary @click="onPasskey">
<MkButton v-if="!queryingKey" type="submit" :disabled="signing" style="margin: auto auto;" rounded large primary @click="onPasskeyLogin">
<i class="ti ti-device-usb" style="font-size: medium;"></i>
{{ signing ? i18n.ts.loggingIn : i18n.ts.signinWithPasskey }}
</MkButton>
Expand Down Expand Up @@ -97,6 +97,7 @@ const totpLogin = ref(false);
const isBackupCode = ref(false);
const queryingKey = ref(false);
let credentialRequest: CredentialRequestOptions | null = null;
const passkey_context = ref('');

const emit = defineEmits<{
(ev: 'login', v: any): void;
Expand Down Expand Up @@ -132,7 +133,7 @@ function onLogin(res: any): Promise<void> | void {
}
}

async function queryKey(): Promise<void> {
async function query2FaKey(): Promise<void> {
if (credentialRequest == null) return;
queryingKey.value = true;
await webAuthnRequest(credentialRequest)
Expand Down Expand Up @@ -161,9 +162,7 @@ async function queryKey(): Promise<void> {
});
}

const passkey_context = ref('');

function onPasskey(): void {
function onPasskeyLogin(): void {
signing.value = true;
if (webAuthnSupported()) {
misskeyApi('signin-with-passkey', {})
Expand All @@ -186,8 +185,8 @@ async function queryPasskey(): Promise<void> {
queryingKey.value = true;
console.log('Waiting passkey auth...');
await webAuthnRequest(credentialRequest)
.catch((er) => {
console.warn('Fail!!', er);
.catch((err) => {
console.warn('Passkey Auth fail!: ', err);
queryingKey.value = false;
return Promise.reject(null);
}).then(credential => {
Expand Down Expand Up @@ -218,7 +217,7 @@ function onSubmit(): void {
publicKey: res,
});
})
.then(() => queryKey())
.then(() => query2FaKey())
.catch(loginFailed);
} else {
totpLogin.value = true;
Expand Down

0 comments on commit ddc98c3

Please sign in to comment.