Skip to content

Commit

Permalink
Provide auth token when uploading files
Browse files Browse the repository at this point in the history
  • Loading branch information
LeBenLeBen committed Apr 1, 2024
1 parent 70c41b6 commit 1de91f0
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/frontend/src/services/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { Directus_Files } from '@/gql/graphql';

import store from '@/store';

export function upload(file: File): Promise<Directus_Files> {
const formData = new FormData();
formData.append('file', file);

const headers = store.state.value.auth?.accessToken
? { Authorization: `Bearer ${store.state.value.auth?.accessToken}` }
: undefined;

return fetch('/files', {
method: 'POST',
body: formData,
headers,
})
.then((response) => response.json())
.then((response) => response.data);
Expand Down

0 comments on commit 1de91f0

Please sign in to comment.