fix: adicionar Authorization header nos fetch diretos do import store

preview e confirm usavam fetch sem o header Bearer, causando 401.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
2026-05-28 22:41:25 -03:00
co-authored by Claude Sonnet 4.6
parent 0f53260f29
commit 26eabc460b
+7 -2
View File
@@ -1,6 +1,11 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
function authHeader(): Record<string, string> {
const token = localStorage.getItem('fc_token')
return token ? { Authorization: `Bearer ${token}` } : {}
}
export interface ImportRow {
date: string
amount: number
@@ -53,7 +58,7 @@ export const useImportStore = defineStore('import', () => {
}
try {
const res = await fetch('/api/imports/preview', { method: 'POST', body: form })
const res = await fetch('/api/imports/preview', { method: 'POST', body: form, headers: authHeader() })
const data = await res.json()
if (!res.ok) throw new Error(data.error ?? 'Erro no preview')
rows.value = data.rows ?? []
@@ -71,7 +76,7 @@ export const useImportStore = defineStore('import', () => {
try {
const res = await fetch('/api/imports/confirm', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json', ...authHeader() },
body: JSON.stringify({
filename: filename.value,
rows: rows.value,