Realtime: v0.10.x JWT文档似乎不清楚?

创建于 2021-01-28  ·  2评论  ·  资料来源: supabase/realtime

问题

使用当前版本的@supabase/realtime-js我无法连接到@supabase/realtime的最新版本。 在记录了v0.10中的重大更改之后,客户端打开请求应该包括哪些内容?

token查询参数? A header

重现

docker-compose.yml

version: "3"
services:
  realtime:
    image: supabase/realtime:latest
    ports:
      - "4000:4000"
    environment:
      DB_HOST: db
      DB_NAME: postgres
      DB_USER: postgres
      DB_PASSWORD: postgres
      DB_PORT: 5432
      PORT: 4000
      HOSTNAME: localhost
      JWT_SECRET: SOMETHING_SUPER_SECRET
      SECURE_CHANNELS: "true"
    depends_on:
      - db
  db:
    image: supabase/postgres
    ports:
      - "5432:5432"
    command:
      - postgres
      - -c
      - wal_level=logical
    environment:
      POSTGRES_PASSWORD: postgres

index.js

const { RealtimeClient } = require("@supabase/realtime-js")

const client = new RealtimeClient("ws://localhost:4000/socket")
client.onOpen(() => console.log("Socket opened."))
client.onClose(() => console.log("Socket closed."))
client.onError((e) => console.log("Socket error", e.message))
client.connect()

终端输出

realtime_1  | 2021-01-28 16:01:20.162 [info] Running RealtimeWeb.Endpoint with cowboy 2.6.3 at :::4000 (http)
realtime_1  | 2021-01-28 16:01:20.162 [info] Access RealtimeWeb.Endpoint at http://localhost:4000
realtime_1  | 2021-01-28 16:03:25.018 [info] REFUSED CONNECTION TO RealtimeWeb.UserSocket in 114µs
realtime_1  |   Transport: :websocket
realtime_1  |   Serializer: Phoenix.Socket.V1.JSONSerializer
realtime_1  |   Connect Info: %{}
realtime_1  |   Parameters: %{"vsn" => "1.0.0"}
realtime_1  | 2021-01-28 16:03:26.033 [info] REFUSED CONNECTION TO RealtimeWeb.UserSocket in 100µs

应用输出

realtime-test-js % node .
Socket error undefined
Socket closed.
Socket error undefined
Socket closed.

预期行为

与实时套接字的连接。

系统信息

  • 操作系统:macOS-docker
  • 实时js版本:1.0.6

最有用的评论

@ w3b6x9很棒,这正是我想要的,谢谢! 试图编写@supabase/realtime-csharp库,并且正在努力了解如何传递token

所有2条评论

@acupofjose我们正在实时启用JWT身份验证,因此如果文档表歉意。

看起来SECURE_CHANNELS $$$已在docker-compose.yml $$$中设置为"true" ,这意味着您必须将JWT_SECRET设置为用于签署JWT的秘密。 然后,您可以像这样传递您的JWT:

const client = new RealtimeClient("ws://localhost:4000/socket", { params: { token: "your_jwt" }})

如果您不想启用JWT身份验证,则可以将SECURE_CHANNELS"false" ,所有内容都应按预期继续运行。 当SECURE_CHANNELS设置为"false" ,您不必设置JWT_SECRET

我将继续更新@supabase/realtime-js文档以反映我在这里写的内容。

如果您还有其他问题,请告诉我。

希望能有所帮助!

@ w3b6x9很棒,这正是我想要的,谢谢! 试图编写@supabase/realtime-csharp库,并且正在努力了解如何传递token

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

awalias picture awalias  ·  6评论

retendo picture retendo  ·  12评论

kiwicopple picture kiwicopple  ·  14评论

awalias picture awalias  ·  5评论

lacoprof picture lacoprof  ·  4评论