More
Authentication
Authentication can be handled through the _onBeforeConnect lifecycle method, which acts as middleware before allowing clients to interact with your actor.
Using _onBeforeConnect
The _onBeforeConnect method is called whenever a new client attempts to connect to your actor. It takes the value of opts.parameters and returns the state to assign to the actor.
Throwing an error in _onBeforeConnect will abort the connection.
Here's a basic example:
TypeScript
Accessing Connection State
After authentication, you can access the connection state in any actor method using rpc.connection.state:
TypeScript
Integration Examples
With API Server Authentication
TypeScript
When authentication fails, throwing an error in _onBeforeConnect will prevent the connection from being established, and the client will receive the error message.
With JWT Authentication
TypeScript