fix: add auth token to ExcelUploader fetch calls
This commit is contained in:
@@ -133,8 +133,10 @@ export default function ExcelUploader({
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
const token = typeof window !== 'undefined' ? localStorage.getItem('accessToken') : null;
|
||||
const response = await fetch(uploadUrl, {
|
||||
method: 'POST',
|
||||
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
||||
body: formData,
|
||||
});
|
||||
|
||||
@@ -159,9 +161,25 @@ export default function ExcelUploader({
|
||||
}
|
||||
}, [file, uploadUrl, onSuccess]);
|
||||
|
||||
const handleDownloadTemplate = useCallback(() => {
|
||||
if (templateUrl) {
|
||||
window.open(templateUrl, '_blank');
|
||||
const handleDownloadTemplate = useCallback(async () => {
|
||||
if (!templateUrl) return;
|
||||
try {
|
||||
const token = typeof window !== 'undefined' ? localStorage.getItem('accessToken') : null;
|
||||
const res = await fetch(templateUrl, {
|
||||
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
||||
});
|
||||
if (!res.ok) throw new Error(`Download failed (${res.status})`);
|
||||
const blob = await res.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = templateUrl.split('/').pop()?.replace('template', 'template.xlsx') || 'template.xlsx';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
} catch (err) {
|
||||
setError('템플릿 다운로드에 실패했습니다.');
|
||||
}
|
||||
}, [templateUrl]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user