Admin
callback hell 😵💫 I highly recommend using try/await/catch instead of promises and nested callbacks.
what exactly are your full console logs with this code?
Votes
0
Replies
24
Participants
Unknown
Messages
25
Admin
callback hell 😵💫 I highly recommend using try/await/catch instead of promises and nested callbacks.
what exactly are your full console logs with this code?
Rank 1: Thread
I prefer not to use try catch because I generally have no idea where the error was thrown. The logs in then() and catch() both run. And the error was mentioned above
Admin
I prefer not to use try catch because I generally have no idea where the error was thrown.
Why not?
And the error was mentioned above
I was asking for the console logs that show the full output of:
console.log("New session created: ")
console.log(response); // Success
console.log({userId} )
console.log("Error when update URL SESSION")
console.log("Success getting session")
console.log(response); // Success
Rank 1: Thread
So I actually figure out why, so Appwrite failed to set cookie so that's why I'm seeing cookieFallback in my localStorage. My understanding now is to set mydomain.com -> appwrite.mydomain.com so that Appwrite can set cookie in my browser. However, I'm hosting my app on vercel so that would be *.vercel.app, is there any alternative way?
Rank 1: Thread
Shouldn't there be a prvider access token be returned so that I can set cookie manually? { "$id": "647a1790f3101a8be71b", "$createdAt": "2023-06-02T16:23:45.007+00:00", "userId": "6479f90459eb835c464e", "expire": "2024-06-01 16:23:44.995", "provider": "magic-url", "providerUid": "", "providerAccessToken": "", "providerAccessTokenExpiry": "", "providerRefreshToken": "", "ip": <MY IP ADDRESS>, "osCode": "MAC", "osName": "Mac", "osVersion": "10.15", "clientType": "browser", "clientCode": "CH", "clientName": "Chrome", "clientVersion": "113.0", "clientEngine": "Blink", "clientEngineVersion": "113.0.0.0", "deviceName": "desktop", "deviceBrand": "Apple", "deviceModel": "", "countryCode": "ca", "countryName": "Canada", "current": true }
Rank 1: Thread
As you can see it's an empty string here
Rank 1: Thread
this is the response from const response = await account.updateMagicURLSession(userId, secret);
Admin
Appwrite sets the cookie regardless...the problem is your browser can block 3rd party cookies from being sent in future requests. The ensure the cookie is a 1st party cookie, they must share the same base domain. In production, you would have your own domain that you can set up. If you don't have a domain, you can modify the hosts entry on your machine for local development.
That said, the fallback header should work still...
Admin
this is expected. that provider access token is for OAuth2 sessions and the token is the token from the OAuth2 provider
Rank 1: Thread
uhmmm the fallback header set session cookies in the localStorage. So what would be your recommendation to handle in this situation ? Perhap, retrieve it from localstorage manually and then set cookies? so that after you can call account.get() ?
Admin
it should all be done automatically...what's your platform?
Rank 1: Thread
I'm using Nextjs and setting hostname as localhost
Admin
nextjs...so it won't work if the account.updateMagicURLSession(userId, secret) is done server side. because the cookie wouldn't exist client side
Rank 1: Thread
I don't see any cookie is set...
Rank 1: Thread
i'm doing account.updateMagicURLSession(userId, secret) in the useEffect()
Admin
where are you looking?
Rank 1: Thread
Rank 1: Thread
I checked session storage and cookies as well
Rank 1: Thread
nothing was there
Admin
but you're probably on your client app. the cookie won't be on your client app. it would be on your appwrite instance. so browse to your appwrite instane and do the same thing
Rank 1: Thread
I'm doing it through the cloud sdk...
Admin
you mean Appwrite Cloud? Then check the cookies when on Appwrite Cloud...
Rank 1: Thread
I might be dumb, how exactly can I check the cookies when on Appwrite Cloud ?
Admin
Browse to the appwrite cloud console and do the same thing here
Rank 1: Thread
I'm just gonna set it up manually from the fallback cookie since my browser is blocking it 😆 . Thanks for your support 🙏