Moderator
Okay, from what I'm seeing it uses client side SDK but passes cookies to server side to avoid conflict so a part is executed client sided as I was supposing
Votes
1
Replies
24
Participants
Unknown
Messages
25
Moderator
Okay, from what I'm seeing it uses client side SDK but passes cookies to server side to avoid conflict so a part is executed client sided as I was supposing
Rank 4: Virtual Machine
The thing is, I don't mind using only Rest API, but the docs are kind of minimal and I have no clue how to properly implement the auth using just rest api.
I understand fetching and everything, but what data do I store? do i store it as localstorage like the client sdk? and what does the key/value need to be?
What if I want to create a JWT?
It says just this
POST /v1/account/jwt HTTP/1.1
Host: HOSTNAME
Content-Type: application/json
X-Appwrite-Response-Format: 1.4.0
X-Appwrite-Project: 5df5acd0d48c2
But how does the rest api know who the user is? I feel like there's chunks missing
Have you read through this? https://appwrite.io/docs/apis/rest#authentication
Rank 4: Virtual Machine
That actually helps a lot, thanks Steven!
One more question about JWT actually, why is there a legacy sometimes popping up in the cookies using the client sdk?
Rank 4: Virtual Machine
a_session_projectid_legacy for example
Rank 4: Virtual Machine
It's not consistent, it's very random on logging-in, as I think the client sdk uses localstorage instead of cookies, so it makes even less sense
The only difference is the samesite option. The legacy one doesn't specify anything for that for backwards compatiblity or something
Rank 4: Virtual Machine
Ah, alright
Rank 4: Virtual Machine
TL;DR, You should use Rest API if you use edge runtime
Rank 4: Virtual Machine
Hey @Steven, Do I need both cookies?
Or is just the a_session_projectid enough?
Rank 4: Virtual Machine
The thing I don't understand, is if you got for example a cookie called a_session_projectid with the value eyJpZCI6IjY1NTI1ZW...TE3MjBiMTdjOSJ9, and I try to fetch /v1/account with that value using rest api fetched via client, it just says 401
Rank 4: Virtual Machine
As far as I understood it, you only need to create a JWT if you want the server to fetch for example, right?
Rank 4: Virtual Machine
nvm, seems I got it working!
Thanks everyone for helping with this topic! Setting it as solved.
Rank 4: Virtual Machine
[Solved] Window not defined | Edge runtime not supported
Yes that one should be enough
Hey how were you able to resolve the problem?
Rank 4: Virtual Machine
Hey. Are you using nextjs?
Yes
Rank 4: Virtual Machine
use rest api instead of client sdk
Can you give me kind of pseudo overview on how to use this
With the rest apiece
Rank 4: Virtual Machine
See reference on docs
I simply send jwt tokens along the request and authenticate that?
Rank 4: Virtual Machine
You set the token as a cookie with secure and httponly, you use the "Cookie" header as authentication
Thanks