Skip to content
Back

Retrieving a session

  • 0
  • Auth
  • Cloud
cryptobitez
16 Feb, 2025, 21:01

The guide for server side auth states users should use the cookie secret to validate a user :

TypeScript
account= Account(sessionclient).setsession(cookie) 
account.get()

How would i retrieve a session, i don't want to set a new session on each login?? getsession seems to take sessionid as a parameter....but the guide on appwrite says the cookie should be set as the secret. so how does that work? seet another cookie or store in local storage the session id?

TL;DR
Developers are having trouble understanding how to retrieve a session and validate a user using Appwrite. The issue seems to stem from confusion around where to store the session ID and the concept of persisting the session. The solution involves persisting the session in a single cookie, as well as setting the session using the cookie secret. This way, you can validate the session without creating a new one each time.
Steven
16 Feb, 2025, 21:19

Yes, you have to persist on login. Something has to persist somewhere.

Set another cookie? What do you mean?

cryptobitez
16 Feb, 2025, 21:25

what do you mean persist on login? - by set another cookie i mean set another cookie with the session id so the getsession function works

Steven
16 Feb, 2025, 21:28

A session must be persisted. The session can be persisted in a single cookie. When you say "another" it sounds like there are multiple, but I'm not sure what other cookies you're referring to

cryptobitez
16 Feb, 2025, 21:34

the guide says i should set the cookie as the 'secret' when a session is created. The cookie is validated in the code i've mentioned- i.e setsession(cookie secret). How can i validate a session?? set session seams to create a session everytime it is called .....I want to validate an existing session. what im asking is as simple as it gets. How can someone validate an authorised user....your guide only mentions a cookie with a secret value inside. This cannot be used to get_session() as that func requires a session id....so how does appwrite suggest i manage the sesssion id?another cookie? i already have a persisted cookie with the secret.

Steven
16 Feb, 2025, 21:35

You validate the session by making an account.get() API call.

There is no ID you need to keep track of

cryptobitez
16 Feb, 2025, 21:51

sir......account .get needs to be set by a cookie according to your guide! Account(sessionclient).setsession(cookie) -----> account.get() if i just call account.get() how will it know who's account? This is incorrect. What i'm asking is painfully simple.

cryptobitez
16 Feb, 2025, 21:59

it also seems to create a newsession each time setsession is called. This not how validating a user works.

cryptobitez
16 Feb, 2025, 21:59

I want to validate a user ie use get session. getsession func requires session id whch i have not been advised on how or where to store.

Steven
16 Feb, 2025, 21:59

client.setSession() sets the session on the client so that all subsequent requests with that client will make the authenticated request.

Steven
16 Feb, 2025, 22:00

Not sure what you're talking about. SetSession doesn't make any API calls. It just sets a property in the Client object

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