Back

✅ [SOLVED] Droplet and App in DigitalOcean

  • 0
  • Accounts
  • Web
Binyamin
22 Mar, 2023, 13:06

Okay got it, and what is github redirect url?

TL;DR
The user was experiencing an issue with cookies not being visible in their application when accessing a certain subdomain. However, it was clarified that the cookies were indeed being set and could be seen when accessing the API directly. It was suggested to check the code flow and ensure that the account login and getting functions were being executed on the frontend code of the correct subdomain. It was also recommended to check the GitHub redirect URL. The issue was resolved when the user realized that they were not running the `account.get()` function in the correct part of their code.
Binyamin
22 Mar, 2023, 13:15

I checked your project and no request is being made to api.imda.cl Maybe you're running the account.get() function in the server side of your next project? In that case you wont get cookie unless you're going to use a cookie jar or JWT

What I mean is the account login and getting should run from the intranet.imda.cl frontend code, the code that is exposed to the end user.

Binyamin
22 Mar, 2023, 13:19

In what part of your code are you running appwrite.account.get()?

Guille
22 Mar, 2023, 13:20

I have disabled to make some debug testing, but even without call to account.get() the cookie should be created

Binyamin
22 Mar, 2023, 13:21

It should but only if the function createOAuth2Session is being execute in a the frontend Where you run this functions?

Binyamin
22 Mar, 2023, 13:23

Oh now I see it

Binyamin
22 Mar, 2023, 13:23

My bad

Guille
22 Mar, 2023, 13:23

I run createOAuth2Session when I click the button

TypeScript
const login = () => createOAuth2Session();

<Button className={classes.loginButton} onClick={login}>Iniciar sesión</Button>
Binyamin
22 Mar, 2023, 13:38

Can you add at the the flow of checking if the account is logged in in the component mounting point? Maybe something like this?

TypeScript
const account = new Account(client);

  try {
   const user         = await account.get();
   console.log(user.email);
  } catch (e) {
   console.log('User is not logged in');
  }
Guille
22 Mar, 2023, 13:48

Done I can see the user email, so the session is created, it just doesn't create the cookie 🤔

Binyamin
22 Mar, 2023, 13:50

Good, In Appwrite you don't need the cookie The flow for your app can be something like this

  1. Check if the user is logged in
  2. if indeed is logged in then store the user object in a global state
  3. Then show view conditionally based on the user state

Is that make sense?

Guille
22 Mar, 2023, 13:55

I have been working with the cookie since v0.7.x 🤔 (not in production)

I can see in the code that response includes a cookie: https://github.com/appwrite/appwrite/blob/master/app/controllers/api/account.php#L613

Binyamin
22 Mar, 2023, 14:02

I think I got it If you would go to this url https://api.imda.cl/v1/ you would see the cookies The cookies are connect to the Appwrite endpoint

Drake
22 Mar, 2023, 15:47

if you were able to get the email, then there is a session/cookie (unless there was the x-local-fallback header in the request) 🧐

what makes you say there is no cookie?

Guille
22 Mar, 2023, 15:50

in the application tab there is no cookie, although I see it when I try it in localhost 🤔

Guille
22 Mar, 2023, 15:51

but as @Binyamin mention if I go to https://api.imda.cl/v1/ the cookie is there

Guille
22 Mar, 2023, 15:53

so the subdomain intranet.imda.cl can't see the cookies from api.imda.cl 🤔

Guille
22 Mar, 2023, 15:54

I'm looking information why is that happening

Binyamin
22 Mar, 2023, 15:54

It doesn't need to as the session management is between the user and the Appwrite engine

Drake
22 Mar, 2023, 15:55

uhhh not exactly....the client app will send the cookie if hte browser has the cookie...that's probably why the account.get() worked

Guille
22 Mar, 2023, 16:00

you're right If I see the output of the cookies with (nextjs)

TypeScript
console.log(req.cookies);

I can see the cookie setted

Guille
22 Mar, 2023, 16:01

I'll change this as resolved as my question was answered, thank you both @Steven @Binyamin

Guille
22 Mar, 2023, 16:02

✅ [Solved] Droplet and App in DigitalOcean

Guille
22 Mar, 2023, 16:04

✅ [SOLVED] Droplet and App in DigitalOcean

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