Back

[SOLVED] getInitials return empty avatar even when the user is logged in

  • 0
  • Web
  • Avatars
Bill.IHCha
16 Sep, 2023, 02:01

I called avatars.getInitials() after client.get() still getting a pure pink avatar

TL;DR
Issue: The getInitials function is returning an empty avatar even when the user is logged in. Solution: The issue is related to image optimization in Next.js. Switching from `<Image />` to `<img />` resolved the problem. This is because Next.js uses its own image optimization and sends the request from the server, not the client. Additionally, there may be a problem with cookies, particularly if the Appwrite endpoint is a subdomain of the app. Using first-party cookies should work fine, but third-party cookies may cause issues. Checking the version of Appwrite (v1.4.3) and the SDK
Bill.IHCha
16 Sep, 2023, 02:01

I could just use the name provided with client.get but I'm wondering if this is a bug or something

Drake
16 Sep, 2023, 15:00

What version of Appwrite and what version of the SDK?

If you log in with someone else what do you see?

Bill.IHCha
16 Sep, 2023, 22:19

Wdym someone else? Appwrite v1.4.3 SDK v13 I think

Drake
16 Sep, 2023, 22:27

I meant a different user account

Although actually I think this might be a 3rd party cookie problem...is your Appwrite endpoint a subdomain of your app? (e.g. appwrite.myapp.com for myapp.com)?

Bill.IHCha
16 Sep, 2023, 22:41

I'm using localhost

Bill.IHCha
16 Sep, 2023, 22:42

But how can it be a cookie problem when I can fetch user account and session?

Bill.IHCha
16 Sep, 2023, 22:42

I have tried logging out and in before

Drake
16 Sep, 2023, 22:54

And is your Appwrite domain localhost too?

Bill.IHCha
16 Sep, 2023, 22:54

No

Bill.IHCha
16 Sep, 2023, 22:54

Development environment

Bill.IHCha
16 Sep, 2023, 22:55

But if it cookie problems, how does appwrite cloud handle it?

D5
16 Sep, 2023, 23:06

If you're using the same domain for your Appwrite instance and website, you will not face problems since it's the same domain, so it will be first party cookies. If not, it will be third party cookies and due to that it could fail

D5
16 Sep, 2023, 23:11

Then it's localhost

Bill.IHCha
16 Sep, 2023, 23:17

I use the same database both in dev and production lol

Bill.IHCha
16 Sep, 2023, 23:18

But I could just get the user account and use the name it provided

Drake
16 Sep, 2023, 23:30

People set up custom domains in Appwrite cloud

Drake
16 Sep, 2023, 23:30
Bill.IHCha
16 Sep, 2023, 23:34

Ah okay thanks. I'll try with all protection disabled later, and also check localStorage

Bill.IHCha
17 Sep, 2023, 03:10

I found the problem, and I think it should probably be documented. I have checked the network request and realised the request was being sent from /_next/image?url=xxx. That means the cookies are not persisted because Nextjs use it's own image optimisation and sent a request from the server not the client. When I switch from next/image's <Image /> to <img /> it worked fine.

Drake
17 Sep, 2023, 05:35

Interesting..nextjs is such a pain 😜

Bill.IHCha
17 Sep, 2023, 05:36

haha, it's just image optimization, so I think it should be pretty common

Bill.IHCha
17 Sep, 2023, 05:36

[SOLVED] getInitials return empty avatar even when the user is logged in

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