plebdevs/src/hooks/encryption/useDecryptContent.js
2025-04-02 17:47:30 -05:00

31 lines
767 B
JavaScript

import { useState } from 'react';
import axios from 'axios';
export const useDecryptContent = () => {
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState(null);
const decryptContent = async encryptedContent => {
setIsLoading(true);
setError(null);
try {
const response = await axios.post('/api/decrypt', { encryptedContent });
if (response.status !== 200) {
throw new Error('Failed to decrypt content');
}
const decryptedContent = response.data.decryptedContent;
setIsLoading(false);
return decryptedContent;
} catch (err) {
setError(err.message);
setIsLoading(false);
return null;
}
};
return { decryptContent, isLoading, error };
};