Skip to content

Commit

Permalink
fix: use api_token in body of form data instead of headers
Browse files Browse the repository at this point in the history
- this is because of headers not being forwarded on redirects
  • Loading branch information
Vexcited committed Aug 13, 2023
1 parent 0d5d917 commit ecddc34
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/utils/files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ export const makeFileUpload = async (files: FileList | Array<File>, options?: {
}

// Only add headers for authenticated users.
const headers: Record<string, string> = {};
if (auth.profile) {
headers.authorization = auth.profile.api_token;
body.set("api_token", auth.profile.api_token);
}

const response = await fetch("/api/workspace/upload", {
method: "PUT",
headers,
body
});

Expand Down
9 changes: 4 additions & 5 deletions supabase/functions/upload-file/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ const json = <T>(data: T, options?: { status: number }) => new Response(
*/
serve(async (req: Request) => {
if (req.method === "PUT") {
const api_token = req.headers.get("authorization");

let user_profile: UserProfile | undefined;
if (api_token) (user_profile = await getUserProfile(api_token));

const formData = await req.formData();
const formDataFiles = formData.getAll("files") as File[];
const formDataApiToken = formData.get("api_token") as string | undefined;

let user_profile: UserProfile | undefined;
if (formDataApiToken) (user_profile = await getUserProfile(formDataApiToken));

const workspaceId = (formData.get("workspace_id") as string | undefined) ?? user_profile?.root_workspace_id ?? undefined;

Expand Down

0 comments on commit ecddc34

Please sign in to comment.