Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server Error Uncaught ConvexError: you do not have access to this org. hasAccessToOrg and getUser are both declared but never read. #5

Open
SlippyDong opened this issue Apr 5, 2024 · 4 comments

Comments

@SlippyDong
Copy link

SlippyDong commented Apr 5, 2024

hasAccessToOrg and getUser are both declared but never read in files.ts and users.ts. It seems there's some logic missing to make this work correctly.
image
image

The YT video about orgId authorization is a bit messy/unclear and the code shown in the video doesn't match the repo:
https://www.youtube.com/watch?v=27hMNWcsa-Y&t=3765s

I can upload files to the convex db and see those files under "files" in the Convex DB, but the data table is empty: No files and no users.
image

image

Although the files can be uploaded, the toast is shown every time: ConvexError: you do not have access to this org.
image

The console error is:
[CONVEX M(files:createFile)] [Request ID: 15ff8b3cefe2071a] Server Error
Uncaught ConvexError: you do not have access to this org
at handler (../convex/files.ts:66:4)

I've tried with a "normal" user and an organization user, but this makes no difference. The error persists with both a user with or without and organization.

Everything else is working nicely, but I can't figure out the logic to make this work or fix it. Please fix this issue and update the main or add a branch with this fix @webdevcody

@caoyacheng
Copy link

same error

@Rope-a-dope
Copy link

It's because we need to set CLERK_HOSTNAME in Convex Environment Variables, not in env.local file. Otherwise, tokenIdentifier created will be https://underfined| $=***. But there is another problem, if we upload txt file ,will show the same toast, but the file will still be created.

@Rope-a-dope
Copy link

Rope-a-dope commented Jul 13, 2024

Second problems fixed. The reason why the incorrect file type is still uploaded is because we already have a post reqeust to post that file to url, the createFile is just to create an entry in files table. So before post, we must check the fileType first and toast the message, return.

if (!orgId) return;

const fileType = values.file[0].type;

if (fileType in types) {
} else {
  toast({
    variant: "destructive",
    title: "File type must be image, pdf or csv",
    description: "Your file could not be uploaded, try again later",
  });
  return;
}

const postUrl = await generateUploadUrl();

const result = await fetch(postUrl, {
  method: "POST",
  headers: { "Content-Type": fileType },
  body: values.file[0],
});
const { storageId } = await result.json();

@devilra
Copy link

devilra commented Oct 24, 2024

Second problems fixed. The reason why the incorrect file type is still uploaded is because we already have a post reqeust to post that file to url, the createFile is just to create an entry in files table. So before post, we must check the fileType first and toast the message, return.

if (!orgId) return;

const fileType = values.file[0].type;

if (fileType in types) {
} else {
  toast({
    variant: "destructive",
    title: "File type must be image, pdf or csv",
    description: "Your file could not be uploaded, try again later",
  });
  return;
}

const postUrl = await generateUploadUrl();

const result = await fetch(postUrl, {
  method: "POST",
  headers: { "Content-Type": fileType },
  body: values.file[0],
});
const { storageId } = await result.json();

this code is solved ok or not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants