使用当前版本的@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.
与实时套接字的连接。
@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
。
最有用的评论
@ w3b6x9很棒,这正是我想要的,谢谢! 试图编写
@supabase/realtime-csharp
库,并且正在努力了解如何传递token
。