79597537

Date: 2025-04-29 03:02:56
Score: 1.5
Natty:
Report link

how to validate appwrite user sessions from backend without using frontend sdks?

you’re almost there. using the server sdk and calling account.getSession(sessionId) is technically correct, but appwrite expects that the session ID is tied to a real cookie in the request (the session cookie like a_session_<projectid>).
just calling getSession(sessionId) server-side without that cookie doesn’t feel "natural" to appwrite sometimes, and then it cries "unauthorized"

the super clean way would be:

problem is — appwrite server sdk doesn’t easily allow sending raw cookies manually because it's made for "server-side trusted" calls
so the workaround is:


is it possible to securely auth frontend -> custom backend -> appwrite using only sessions?

yeah it's possible. it's actually the ideal old-school "session based auth" way.

flow would be:

  1. frontend logs in normally using appwrite sdk → gets session

  2. frontend stores the session cookie (automatic if you’re using browser / for react native you gotta manually do it)

  3. frontend sends requests to your api gateway, carrying the session cookie

  4. your gateway extracts the session cookie, validates the session (like i said above, direct rest call to appwrite’s /account endpoint)

  5. if appwrite says user is good, allow request to microservices

you never need jwt this way unless you want scalability across multi-clusters or mobile + web SSO type stuff later


best scalable approach if session is messy?

if one day this session way feels annoying (like cookie management in mobile gets painful)
then you gotta move to a hybrid model:

but bro seriously unless you’re scaling like crazy (like millions of concurrent users)
session auth is clean, simpler, and you can scale it horizontally by using sticky sessions or redis session storage if needed.


quick quick version of the right flow you can try right now

  1. frontend saves and sends session cookie manually

  2. fastapi gets cookie, calls https://cloud.appwrite.io/v1/account (with cookie header) inside a simple requests.get() (python’s requests lib)

  3. if 200 ok → user is valid

  4. attach user info to request context and forward it to microservices

no need jwt, no need to refresh session, no drama

Reasons:
  • Blacklisted phrase (1): is it possible to
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): how to
  • Low reputation (1):
Posted by: Monkey.D Amith