Skip to content

Commit 1a24366

Browse files
committed
refactor: centralize clipboard and two-factor authentication logic, enhance state management, and optimize TwoFactor UI components
1 parent 14f1165 commit 1a24366

File tree

3 files changed

+285
-203
lines changed

3 files changed

+285
-203
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { ref } from 'vue';
2+
3+
interface ClipboardOptions {
4+
timeout?: number;
5+
}
6+
7+
export function useClipboard(options: ClipboardOptions = {}) {
8+
const { timeout = 1500 } = options;
9+
10+
const copied = ref(false);
11+
12+
const copyToClipboard = async (text: string): Promise<void> => {
13+
if (typeof window === 'undefined' || !navigator.clipboard) {
14+
return;
15+
}
16+
17+
try {
18+
await navigator.clipboard.writeText(text);
19+
copied.value = true;
20+
setTimeout(() => (copied.value = false), timeout);
21+
} catch (error) {
22+
console.error('Failed to copy to clipboard:', error);
23+
}
24+
};
25+
26+
return {
27+
copied,
28+
copyToClipboard,
29+
};
30+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export const useTwoFactorAuth = () => {
2+
const fetchQRCode = async (): Promise<{ svg: string }> => {
3+
const response = await fetch(route('two-factor.qr-code'));
4+
return await response.json();
5+
};
6+
7+
const fetchManualSetupKey = async (): Promise<{ secretKey: string }> => {
8+
const response = await fetch(route('two-factor.secret-key'));
9+
return await response.json();
10+
};
11+
12+
const fetchRecoveryCodes = async (): Promise<string[]> => {
13+
const response = await fetch(route('two-factor.recovery-codes'));
14+
return await response.json();
15+
};
16+
17+
return {
18+
fetchQRCode,
19+
fetchManualSetupKey,
20+
fetchRecoveryCodes,
21+
};
22+
};

0 commit comments

Comments
 (0)