
when i'm logging in and creating email session from client web sdk, it logs in user and creates and assigns cookie in cookie tab in developer tools, and also a fallback cookie in localstorage,
but when i refresh the cookie from cookie tab vanishes, may i know why is that? also the localStorage fallback cookie is still there (because session is not deleted yet, i.e, logout)
i'm trying to use middleware.js in next js to intercept the reqeust, if user manually changes the url, i need to redirect user, but since cookie vanishes from cookies tab i dont know how to achieve this?
please help

What are you using for your endpoint And is your app running on localhost?

Endpoint: Appwrite cloud And yes localhost currently, later have to upload to ubuntu machine in aws

So cookies are tied to the domain, not the app. So the cookies will be visible if you browse to the domain.
Because the domains are different, you'll probably also run into a problem where the Appwrite cookie isn't sent to Appwrite because it's considered a 3rd party cookie. To solve that, you'll need a custom domain: https://appwrite.io/docs/advanced/platform/custom-domains

Okay got it, need a custom domain, with an appwrite subdomain to stabalise the cookie, Since it's not working on localhost I need to develop and deploy, then check if cookie is working

To test locally, maybe you can edit your hosts file to fake using a domain

Another thing about nextjs is if you're using server side rendering, you may run into problems because the session is client side and not server side

Wow is it possible to do that, have to check that..
Yes thankyou so much for your help

hi Steven, I've got similar issues (but not exactly the same) trying to get appwrite auth working with nextjs (self hosted appwrite instance on a live domain (docker install on a ubuntu server, which itself runs smoothly and the dashboard is available live and works like a charme)): I managed to set the cookies using a nextjs route service, (at least I think they are set, since I can not have a look at them due to the discussed domain restriction)...but then when I try to trigger verification using another route file, it does not work out...any ideas...? object which i'm setting using nextjs' response.cookie.set() function: { a_session_653bd1dc5c2abcd7d741: 'eyJpZCI6IjZm....', expires: 'Mon, 25-Nov-2024 17:36:39 GMT', path: '/', domain: '.api.example.com', secure: 'true', httponly: 'true', samesite: 'None' } for example...is the dot in front of the "api.example.com" correct....?

maybe i should note, that i am trying to work from localhost, but the nextjs server/route itself does the POST request to the api domain, and receives the above mentioned object, then i am trying to set the cookie, returning the response with the appropriate data set as header/cookies using nextjs response.cookies.set(obj) function. That works and sets cookies correctly, as long as i filter out {domain: ".api.domain.com"} from the object. But i guess this is working, and i just can not see/read it, since i am not asking from the api-domain. If thats true, how does my verification not work out? IT shoud be a PUT request, as far as i know....and its code is similarly set up as in the above mentioned .../account/sessions/email request, but only for .../account/verification

You shouldn’t be setting the cookies yourself - the SDK should be setting them

also using REST / server side sessions? I could not imagine what for they'd publish some docs like this: https://appwrite.io/docs/references/cloud/server-rest/account (see platform dropdown on the upper right side (desktop version)) ... the thing is i am using nextjs server components / app-router, which decouples lot of stuff, from the original way to do it, using only plain react

but maybe you are right, do you know it for sure, not to use set them manually, also using REST/nextjs?

Please create a separate post instead of posting in another person's thread

does this really make sense, in this case (regarding the title/header/subject name of this post/thread) - for sure if you think it does, i'll do so, but I thougt its not the person which is in focus, but the topic...

Hey!
If this is solved for you, make sure to edit your thread title in the beginning with [Solved], Thanks! 😄

[SOLVED!] Next js Appwrite cookie

i shifted to flask for manual authentication and currently using only database from appwrite, with flask i can handle cookies and session with next js manually, but with appwrite, i need a separate domain to that or edit host files or even after that it may not work, or something will break with nextjs, etc. which is out of my way to do things i think.. but someone who has time to make it work and get to the bottom of this can try it out, ( since we can make it better by using it more ) since im on a time crunch, i thought this was the best solution for me currently, thankyou so much
Recommended threads
- Where is tensorflow support? 3.11 ML doe...
and if i manually tried to add tensorflow i get Cannot access offset of type string on string no matter what
- OAuth2 Error: invalid success param url ...
Hi everyone! I'm trying to implement Google OAuth2 login in a React Native app (using the Android simulator) with Appwrite Cloud, and I'm getting the following ...
- Relationships restricted to a max depth ...
When I do query like: ``` await _databases.listDocuments( databaseId: AppwriteConfig.DATABASE_ID, collectionId: AppwriteConfig.SERVICES_COLLECTI...
