Skip to content

Websockets example code is wrong #2845

Open
@infomiho

Description

@infomiho

On this page: https://wasp.sh/docs/advanced/web-sockets#websocketfn-function

We tell users to get the username like this:

import { getFirstProviderUserId } from 'wasp/auth'

// ...

const username = getFirstProviderUserId(socket.data.user) ?? 'Unknown'

But... getFirstProviderUserId expects a UserWithAuthEntity while socket.data.user is an AuthUser and has been since version 0.14.0. This causes a type error and it doesn't work.

The correct way to get the username (from our waspc/examples/todoApp:

const username = socket.data.user?.getFirstProviderUserId() ?? "Unknown";

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationshouldfixWe should do/fix this at some point

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions