mirror of
https://github.com/wasp-lang/wasp.git
synced 2024-12-26 10:35:04 +03:00
Fixed obtaining username in web socket docs to work for new auth.
This commit is contained in:
parent
eb93a89e9a
commit
b19907b431
@ -71,10 +71,11 @@ This is how we can define our `webSocketFn` function:
|
||||
|
||||
```ts title=src/server/webSocket.js
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { getFirstProviderUserId } from '@wasp/auth/user.js'
|
||||
|
||||
export const webSocketFn = (io, context) => {
|
||||
io.on('connection', (socket) => {
|
||||
const username = socket.data.user?.email || socket.data.user?.username || 'unknown'
|
||||
const username = getFirstProviderUserId(socket.data.user) ?? 'Unknown'
|
||||
console.log('a user connected: ', username)
|
||||
|
||||
socket.on('chatMessage', async (msg) => {
|
||||
@ -92,10 +93,11 @@ export const webSocketFn = (io, context) => {
|
||||
```ts title=src/server/webSocket.ts
|
||||
import type { WebSocketDefinition, WaspSocketData } from '@wasp/webSocket'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { getFirstProviderUserId } from '@wasp/auth/user.js'
|
||||
|
||||
export const webSocketFn: WebSocketFn = (io, context) => {
|
||||
io.on('connection', (socket) => {
|
||||
const username = socket.data.user?.email || socket.data.user?.username || 'unknown'
|
||||
const username = getFirstProviderUserId(socket.data.user) ?? 'Unknown'
|
||||
console.log('a user connected: ', username)
|
||||
|
||||
socket.on('chatMessage', async (msg) => {
|
||||
@ -332,4 +334,4 @@ The `webSocket` dict has the following fields:
|
||||
|
||||
- `autoConnect: bool`
|
||||
|
||||
Whether to automatically connect to the WebSocket server. Default: `true`.
|
||||
Whether to automatically connect to the WebSocket server. Default: `true`.
|
||||
|
Loading…
Reference in New Issue
Block a user