Skip to content

Commit 3515166

Browse files
committed
fix: make auth optional
1 parent 22e0354 commit 3515166

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/server.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ import { registerYSocketIOServer } from './socketio.js'
88
import http from 'http'
99
import { randomUUID } from 'crypto'
1010

11-
const skipAuth = env.getConf('no-auth') === 'true'
12-
13-
const wsServerPublicKey = await ecdsa.importKeyJwk(
14-
json.parse(env.ensureConf('auth-public-key'))
15-
)
11+
const authPublicKey = env.getConf('auth-public-key')
12+
/** @type {CryptoKey | null} */
13+
let wsServerPublicKey = null
14+
if (authPublicKey) {
15+
wsServerPublicKey = await ecdsa.importKeyJwk(
16+
json.parse(env.ensureConf('auth-public-key'))
17+
)
18+
}
1619

1720
/**
1821
* @param {Object} opts
@@ -34,7 +37,7 @@ export const createYSocketIOServer = async ({
3437
const server = await registerYSocketIOServer(io, store, {
3538
redisPrefix,
3639
authenticate: async (socket) => {
37-
if (skipAuth) return { userid: randomUUID().toString() }
40+
if (!wsServerPublicKey) return { userid: randomUUID().toString() }
3841
const token = socket.handshake.query.yauth
3942
if (!token) return null
4043
// verify that the user has a valid token

0 commit comments

Comments
 (0)