misc_pterodactyl-panel/resources/scripts/api/account/webauthn/getWebauthnKeys.ts

24 lines
677 B
TypeScript
Raw Normal View History

import http from '@/api/http';
export interface WebauthnKey {
id: number;
name: string;
createdAt: Date;
2021-09-11 22:22:58 +00:00
lastUsedAt: Date | undefined;
}
export const rawDataToWebauthnKey = (data: any): WebauthnKey => ({
id: data.id,
name: data.name,
createdAt: new Date(data.created_at),
2021-09-11 22:22:58 +00:00
lastUsedAt: data.last_used_at ? new Date(data.last_used_at) : undefined,
});
export default (): Promise<WebauthnKey[]> => {
return new Promise((resolve, reject) => {
http.get('/api/client/account/webauthn')
.then(({ data }) => resolve((data.data || []).map((d: any) => rawDataToWebauthnKey(d.attributes))))
.catch(reject);
});
};