2021-07-17 18:48:14 +00:00
|
|
|
import http from '@/api/http';
|
|
|
|
|
2021-07-17 19:20:03 +00:00
|
|
|
export interface WebauthnKey {
|
2021-07-17 18:48:14 +00:00
|
|
|
id: number;
|
|
|
|
name: string;
|
|
|
|
createdAt: Date;
|
2021-09-11 22:22:58 +00:00
|
|
|
lastUsedAt: Date | undefined;
|
2021-07-17 18:48:14 +00:00
|
|
|
}
|
|
|
|
|
2021-07-17 19:20:03 +00:00
|
|
|
export const rawDataToWebauthnKey = (data: any): WebauthnKey => ({
|
2021-07-17 18:48:14 +00:00
|
|
|
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,
|
2021-07-17 18:48:14 +00:00
|
|
|
});
|
|
|
|
|
2021-07-17 19:20:03 +00:00
|
|
|
export default (): Promise<WebauthnKey[]> => {
|
2021-07-17 18:48:14 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2021-08-08 17:48:35 +00:00
|
|
|
http.get('/api/client/account/security-keys')
|
2021-07-17 19:20:03 +00:00
|
|
|
.then(({ data }) => resolve((data.data || []).map((d: any) => rawDataToWebauthnKey(d.attributes))))
|
2021-07-17 18:48:14 +00:00
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
};
|