Back

How do I grant the newly created user permission to read their own session on verified?

  • 0
  • Web
  • Accounts
  • Cloud
  • Self Hosted
  • Users
Drake
1 Jun, 2023, 19:09

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?

TL;DR
User wants to grant newly created user permission to read their own session on verified. - User is trying to check the cookies on Appwrite Cloud but is having trouble finding them. - Another user suggests checking the cookies on the Appwrite instance instead of the client app. - User is unable to find the cookies in session storage and cookies. - The user is using Nextjs and setting the hostname as localhost. - Other user explains that browsers can block 3rd-party cookies and suggests modifying the hosts entry for local development. - User is still unable to set the cookie and is not receiving a provider access token. - User discovers that Appwrite
ymihn1
1 Jun, 2023, 20:13

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

Drake
1 Jun, 2023, 21:01

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:

TypeScript
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
ymihn1
2 Jun, 2023, 15:58

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?

ymihn1
2 Jun, 2023, 16:32

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 }

ymihn1
2 Jun, 2023, 16:33

As you can see it's an empty string here

ymihn1
2 Jun, 2023, 16:35

this is the response from const response = await account.updateMagicURLSession(userId, secret);

Drake
2 Jun, 2023, 16:55

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...

Drake
2 Jun, 2023, 16:55

this is expected. that provider access token is for OAuth2 sessions and the token is the token from the OAuth2 provider

ymihn1
2 Jun, 2023, 20:49

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() ?

Drake
2 Jun, 2023, 21:01

it should all be done automatically...what's your platform?

ymihn1
2 Jun, 2023, 21:06

I'm using Nextjs and setting hostname as localhost

Drake
2 Jun, 2023, 21:08

nextjs...so it won't work if the account.updateMagicURLSession(userId, secret) is done server side. because the cookie wouldn't exist client side

ymihn1
2 Jun, 2023, 21:16

I don't see any cookie is set...

ymihn1
2 Jun, 2023, 21:17

i'm doing account.updateMagicURLSession(userId, secret) in the useEffect()

Drake
2 Jun, 2023, 21:18

where are you looking?

ymihn1
2 Jun, 2023, 21:19
ymihn1
2 Jun, 2023, 21:19

I checked session storage and cookies as well

ymihn1
2 Jun, 2023, 21:20

nothing was there

Drake
2 Jun, 2023, 21:20

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

ymihn1
2 Jun, 2023, 21:31

I'm doing it through the cloud sdk...

Drake
2 Jun, 2023, 21:36

you mean Appwrite Cloud? Then check the cookies when on Appwrite Cloud...

ymihn1
2 Jun, 2023, 23:59

I might be dumb, how exactly can I check the cookies when on Appwrite Cloud ?

Drake
3 Jun, 2023, 00:39

Browse to the appwrite cloud console and do the same thing here

ymihn1
3 Jun, 2023, 17:37

I'm just gonna set it up manually from the fallback cookie since my browser is blocking it 😆 . Thanks for your support 🙏

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