Rank 1: Thread
No, I'm using a client sdk. As an individual user.
Votes
0
Replies
24
Participants
Unknown
Messages
25
Rank 1: Thread
No, I'm using a client sdk. As an individual user.
Rank 7: Quantum Computer
Okay, I think I can spot the issue
Rank 7: Quantum Computer
When you're running the account.createEmailSession action the returned cookie are not being sent back in the results.
Rank 1: Thread
I used this same api in an application using react, and when I created the user session, via email, it automatically saved the cookie in the browser, in a way that I still don't understand well (I'm a beginner).
I'm using insomnia to simulate this login, similarly to what I did in react, however I believe that the return data should be the cookie. Only it is not returned.
Rank 7: Quantum Computer
You can see here at
\appwrite\src\client.ts That you never getting back the Cookies you just get the json
And the only you will have those cookies is if you do it in window mode
Otherwise you can use the REST option with JWT
Rank 7: Quantum Computer
In browser it will work
But in your code you can see that the client is node
Rank 7: Quantum Computer
Rank 1: Thread
let me watch it calmly
one moment
Rank 7: Quantum Computer
My suggestion for a quick way around it is it just to add request to get a JWT and send it back with the results, and from then you can connect using the JWT
const result = await account.createEmailSession(email, password);const jwt = await account.createJWT();
return response.status(201).json({ message: "...", data : {result, jwt}});Rank 1: Thread
I'm trying to understand what you're trying to say.
What do you mean I would only get the cookie back in window mode?
In case, I know that in the browser, somehow the cookie is saved and it works. But for me to test on my backend I would need to have a JWT, is that it?
Is there a problem with insomnia requests? I had not tested with postman.
Rank 1: Thread
Sorry for the delay, I have difficulties with the English language.
Rank 7: Quantum Computer
It's bit complex issue
But every time you do a request and cookies are returned they are saved inside a Cookie Jar
When you running this action inside the browser or any other API tester it will take care of the Jar
But, in your situation is not insomnia issue but the node-fetch one where the account functions running on
So when insomnia contacting your endpoint aka create_email_session it have all the cookies, but when your NodeJS app is contacting your AppWrite engine it does that using node-fetch and is not saving the Cookies inside the Jar
Rank 7: Quantum Computer
Can you show me your node package.json?
Rank 1: Thread
Hum, ok. I´ĺl try.
Rank 1: Thread
a little complex for me still.
Rank 1: Thread
for sure.
Rank 1: Thread
Rank 7: Quantum Computer
Every instance can store the cookies inside the jar and provide them when there is a new request but not the node fetch in your case
Rank 7: Quantum Computer
And I don't think you can have a way around it without JWT
Rank 1: Thread
I understand. I'll test with JWT, I hadn't thought of that context. In case, if someone consumes my custom api, in the browser, it wouldn't need to access via JWT, would it?
The JWT would just be for me to test as an authenticated user, right?
Rank 7: Quantum Computer
No
The JWT and all the app data is inside your express code and is not exposed unless you send it somehow
Rank 1: Thread
ok, my friend.
Rank 7: Quantum Computer
👍
Rank 1: Thread
Thank you for your support!
Admin
You could try to manually make the API call using fetch or a axios and checking the response headers for the cookie