Authentication
Authentication can be handled through the onBeforeConnect
or createConnState
lifecycle hook, which acts as middleware before allowing clients to interact with your actor.
Using onBeforeConnect
or createConnState
The onBeforeConnect
and createConnState
hook is called whenever a new client attempts to connect to your actor. It receives a context object that contains the client’s connection parameters. createConnState
should return an object that will become the connection state.
Throwing an error in onBeforeConnect
or createConnState
will abort the connection.
Here’s a basic example:
Accessing Connection State
After authentication, you can access the connection state in any action through the context object:
Integration Examples
With API Server Authentication
When authentication fails, throwing an error in createConnState
will prevent the connection from being established, and the client will receive the error message.