fix: add auth headers to loadCanvas, add canvas import
This commit is contained in:
@@ -64,14 +64,23 @@ export const useCanvas = () => {
|
|||||||
return { nodes, edges }
|
return { nodes, edges }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getAuthHeaders = (): Record<string, string> => {
|
||||||
|
const auth = useAuth()
|
||||||
|
const token = auth.token?.value
|
||||||
|
return token ? { Authorization: `Bearer ${token}` } : {}
|
||||||
|
}
|
||||||
|
|
||||||
const loadCanvas = async (id: string): Promise<CanvasData> => {
|
const loadCanvas = async (id: string): Promise<CanvasData> => {
|
||||||
const data = await $fetch(`/api/canvas/${id}`)
|
const data = await $fetch(`/api/canvas/${id}`, {
|
||||||
|
headers: getAuthHeaders()
|
||||||
|
})
|
||||||
return parseCanvasJson(data)
|
return parseCanvasJson(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateNodeState = async (nodeId: string, state: string) => {
|
const updateNodeState = async (nodeId: string, state: string) => {
|
||||||
return await $fetch(`/api/nodes/${nodeId}`, {
|
return await $fetch(`/api/nodes/${nodeId}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
|
headers: getAuthHeaders(),
|
||||||
body: { state }
|
body: { state }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user