I am currently handling authentication entirely server-side via an /api/auth endpoint, so I don't have any Appwrite client instances running client-side.
However, Realtime requires being authenticated on the client side to stream events the user has access to.
My challenge is how to leverage the SSR auth I already have in place to securely authenticate a client-side Appwrite instance to subscribe to Realtime events. So far, I see two possible approaches:
- Return the session cookie in my server's
/api/authendpoint response and use it to authenticate the client-side Appwrite instance. - Reimplement client-side authentication, separate from my current SSR setup, to authenticate the Appwrite client directly.
For the first approach, I'm concerned that exposing the session cookie to JavaScript (even if it was originally set as httpOnly) opens up security vulnerabilities to XSS attacks or malicious browser extensions. For the second approach, it feels like a step backward in terms of developer experience. Additionally, maintaining both SSR and client-side authentication seems to violate DRY principles.
What’s the best approach to securely set up an authenticated client-side Appwrite Realtime connection without giving up on SSR auth?