Back

Storage not respecting permissions like database does

  • 1
  • Teams
  • Web
  • Databases
  • General
  • Storage
Drake
24 Aug, 2023, 01:58

Is your Appwrite running on localhost?

TL;DR
The user is experiencing issues with storage not respecting permissions. They have tried changing cookie settings and using a regular image tag instead of NextJS's Image component. They also mention that the network request for the image is going through NextJS. The issue may be related to 3rd party cookies being blocked. The user provides some code snippets and mentions their domains. There is no clear solution provided in the thread.
kathelia.dokgu
24 Aug, 2023, 02:01

No it's on domain.com. This is my development environment.

kathelia.dokgu
24 Aug, 2023, 02:02

For my production environment this is what I see.

Drake
24 Aug, 2023, 02:02

What's the URL you're connecting to?

kathelia.dokgu
24 Aug, 2023, 02:03

The custom domain I set up for the project.

Drake
24 Aug, 2023, 02:03

And would you please check the show filtered cookies?

Drake
24 Aug, 2023, 02:03

What's the path?

kathelia.dokgu
24 Aug, 2023, 02:13

The cookies with the yellow background says something like it was blocked because the request URL's domain doesn't exactly match the cookie's domain nor was the request URL's domain, a subdomain of the cookie's domain.

My domains are as follows:

Appwrite: domain.dev NextJS App: anotherdomain.com Custom Domain: appwrite.anotherdomain.com

kathelia.dokgu
24 Aug, 2023, 02:14

My NextJS app uses the custom domain (appwrite.anotherdomain.com) for all requests involving Appwrite. It doesn't use the main Appwrite domain.

kathelia.dokgu
24 Aug, 2023, 02:17

In the screenshot's domain column, it shows .appwrite.anotherdomain.com as the value (notice the period at the start). I'm guessing it's why it says it doesn't exactly match? Because it seems to be the exact (sub) domain other than the period at the start.

kathelia.dokgu
24 Aug, 2023, 02:20

The request URL is https://anotherdomain.com/_next/image?url=https%3A%2F%2Fappwrite.anotherdomain.com%2Fv1%2Fstorage%2Fbuckets%2F64e147551c3f9c7d50f5%2Ffiles%2F64e6bab47f911b0afc35%2Fpreview%3Fproject%3D64b7ee06f16bc1cd9c8d&w=384&q=75.

Drake
24 Aug, 2023, 02:22

That's weird...why is it requested like that?

kathelia.dokgu
24 Aug, 2023, 02:22

I'm using NextJS's Image component imported from next/image.

kathelia.dokgu
24 Aug, 2023, 02:23
TypeScript
import Image from 'next/image';

...

<Image
  src={file.previewImage.href}
  width={300}
  height={300}
  className='max-w-full max-h-full'
  alt=''
/>
Drake
24 Aug, 2023, 02:23

Seems like the request might be proxied through your backend which could explain why the cookie isn't passed

Drake
24 Aug, 2023, 02:24

So it's blocked... this is usually because of 3rd party cookies

kathelia.dokgu
24 Aug, 2023, 02:25

I'm not using my NextJS's backend for this.

TypeScript
const bucketFile = await storage.createFile(Constants.APPWRITE_BUCKET_ID, ID.unique(), file);
const previewImage = await storage.getFilePreview(Constants.APPWRITE_BUCKET_ID, bucketFile.$id);

This is using the web sdk not the server-side.

Drake
24 Aug, 2023, 02:26

No, the period is fine. It's part of the old rfc specs for cookies

kathelia.dokgu
24 Aug, 2023, 02:26

I already allowed all cookies on my browser though?

Drake
24 Aug, 2023, 02:27

But the network request for the image is going through nextjs: https://discord.com/channels/564160730845151244/1142978905058328726/1144093970683678810

kathelia.dokgu
24 Aug, 2023, 02:28

I guess I should try a regular <img /> tag instead of using NextJS's Image component.

Drake
24 Aug, 2023, 02:28

Worth a try ya

kathelia.dokgu
24 Aug, 2023, 02:41

Surprisingly this did fix the issue on both my production instance AND on my localhost - and that's even after I changed my cookie settings to block third party cookies in incognito - I was only expecting that production will be fixed and I'll still have issues on my localhost. Does that mean that images will fail to load if my users don't allow all cookies? Let's say for example my user goes to my app using the incognito mode. No images (from appwrite buckets) are going to display properly?

Drake
24 Aug, 2023, 02:43

In production, you should have appwrite on a subdomain of your app. In that case, the cookie is a 1st party cookie and shouldn't be blocked

kathelia.dokgu
24 Aug, 2023, 02:45

Yes that is the case so it should be fine.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more