[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Bug Report: Realtime does not recognize auth status of Appwrite client instances authenticated with setSession #8925

Open
2 tasks done
mareszhar opened this issue Nov 5, 2024 · 1 comment
Labels
api / realtime Fixes and upgrades for the Appwrite Realtime API. bug Something isn't working product / auth Fixes and upgrades for the Appwrite Auth / Users / Teams services.

Comments

@mareszhar
Copy link

👟 Reproduction steps

When I authenticate a client-side Appwrite instance with client.setSession(sessionCookie), Realtime doesn't recognize the authed status of the instance.

I'm doing SSR auth, and one of my API endpoints in Nuxt returns the session cookie to clients that authenticate successfully. Then, I use that cookie to authenticate the client-side Appwrite instance.

Most requests requiring an authed status work (eg: I can use that same client-side Appwrite instance to fetch user-only collections, etc.) Only Realtime doesn't recognize the authed status of the instance.

I am currently developing in localhost only and my Appwrite endpoint is https://cloud.appwrite.io/v1, so I couldn't configure the session cookie to be automatically sent to Appwrite in addition to localhost.

PS: If any additional context is needed, I first reported this in this Discord thread.

👍 Expected behavior

Realtime recognizes the auth status of Appwrite instances authenticated with client.setSession(), and streams events that conform to the instance's auth status.

This would keep Realtime consistent with all other Appwrite services, which already support instances authenticated with client.setSession(), and spare people doing SSR auth the need to reimplement auth client-side, specially when they can't yet configure a custom Appwrite endpoint.

👎 Actual Behavior

Realtime's auth detection is inconsistent with the rest of Appwrite.

Both account.getSession('current') and accessing a collection where only users have read permission with databases.listDocuments() return the current session and the list of documents, respectively, showing they can detect the auth status of Appwrite instances authenticated with client.setSession(sessionCookie).

But, subscribing to Realtime channels that require being authenticated (like being a user to 'read' a collection) with that same Appwrite instance doesn't work, and the Realtime connection does not stream to the authenticated client any of the events in those channels.

🎲 Appwrite version

Appwrite Cloud

💻 Operating system

MacOS

🧱 Your Environment

Tech stack is just Nuxt and Appwrite. No significant environment customizations in place.

"nuxt": "^3.13.2", "node-appwrite": "^14.1.0", "appwrite": "^16.0.2"

I'm doing SSR auth and then returning the session cookie from my API endpoint to the client when authenticated. I then use that cookie to authenticate the client-side Appwrite instance that goes on to establish the Realtime connection.

// /app/utils/appwrite.ts

import { Account, Client, Databases } from 'appwrite'

export function createClientSideSessionClient(sessionCookie: string | null) {
  const runtimeConfig = useRuntimeConfig()

  const client = new Client()
    .setEndpoint(runtimeConfig.public.appwriteEndpoint)
    .setProject(runtimeConfig.public.appwriteProject)

  if (sessionCookie)
    client.setSession(sessionCookie)

  const account = new Account(client)
  const databases = new Databases(client)

  return { client, account, databases }
}

I'm not really using this client-side client for anything other than Realtime (all requests to data in my Appwrite collections are handled by server-side Appwrite client instances). But, I modified my client-side Appwrite util to return account and databases to test the auth status of my client-side instance.

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

@mareszhar mareszhar added the bug Something isn't working label Nov 5, 2024
@mareszhar mareszhar changed the title 🐛 Bug Report: Realtime does not recognize auth status of Appwrite client instances authenticated wiith setSession 🐛 Bug Report: Realtime does not recognize auth status of Appwrite client instances authenticated with setSession Nov 5, 2024
@DH-555 DH-555 added the product / auth Fixes and upgrades for the Appwrite Auth / Users / Teams services. label Nov 6, 2024
@MaximilianLS98
Copy link

I think I'm experiencing the same difficulties in my Next.js project. Tried having a route handler for fetching the users session cookie from the server side (Next/Headers {cookies}), and then trying to .setSession on the clientside appwrite client, but even then it doesnt recieve any realtime events at all, until i change the permissions of the collection(or thing im listening for) to read=any. I am also able to query for normal things in the database or object storage with the client as an authenticated user. I followed the latest Youtube video from Appwrite for setting up authentication with SSR.

@stnguyen90 stnguyen90 added the api / realtime Fixes and upgrades for the Appwrite Realtime API. label Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api / realtime Fixes and upgrades for the Appwrite Realtime API. bug Something isn't working product / auth Fixes and upgrades for the Appwrite Auth / Users / Teams services.
Projects
None yet
Development

No branches or pull requests

4 participants