mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-21 17:25:44 +03:00
initial commit
This commit is contained in:
42
frontend/src/lib/services/webauthn-service.ts
Normal file
42
frontend/src/lib/services/webauthn-service.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import type { Passkey } from '$lib/types/passkey.type';
|
||||
import type { User } from '$lib/types/user.type';
|
||||
import type { AuthenticationResponseJSON, RegistrationResponseJSON } from '@simplewebauthn/types';
|
||||
import APIService from './api-service';
|
||||
import userStore from '$lib/stores/user-store';
|
||||
|
||||
class WebAuthnService extends APIService {
|
||||
async getRegistrationOptions() {
|
||||
return (await this.api.get(`/webauthn/register/start`)).data;
|
||||
}
|
||||
|
||||
async finishRegistration(body: RegistrationResponseJSON) {
|
||||
return (await this.api.post(`/webauthn/register/finish`, body)).data as Passkey;
|
||||
}
|
||||
|
||||
async getLoginOptions() {
|
||||
return (await this.api.get(`/webauthn/login/start`)).data;
|
||||
}
|
||||
|
||||
async finishLogin(body: AuthenticationResponseJSON) {
|
||||
return (await this.api.post(`/webauthn/login/finish`, body)).data as User;
|
||||
}
|
||||
|
||||
async logout() {
|
||||
await this.api.post(`/webauthn/logout`);
|
||||
userStore.clearUser();
|
||||
}
|
||||
|
||||
async listCredentials() {
|
||||
return (await this.api.get(`/webauthn/credentials`)).data as Passkey[];
|
||||
}
|
||||
|
||||
async removeCredential(id: string) {
|
||||
await this.api.delete(`/webauthn/credentials/${id}`);
|
||||
}
|
||||
|
||||
async updateCredentialName(id: string, name: string) {
|
||||
await this.api.patch(`/webauthn/credentials/${id}`, { name });
|
||||
}
|
||||
}
|
||||
|
||||
export default WebAuthnService;
|
||||
Reference in New Issue
Block a user