Authentication Forwarding

Forward your app's existing authentication to the StreamLayer SDK, use anonymous auth for apps without login, or manage the SDK auth state programmatically.

Authentication Forwarding

The StreamLayer SDK provides a rich set of features. Some of them — Chat, Who's Watching, Gamification, and Betting — require user authentication. The SDK offers several authentication strategies so you can choose the one that best fits your app.

Bypass Authentication

If your host app already authenticates users with a token-based system, you can forward that token to the StreamLayer SDK. This way your users are authenticated automatically and do not need to sign in again inside the SDK.

await StreamLayer.authorizationBypass("schema", "token")

The SDK sends the token to the StreamLayer backend. If the response is successful, a user entry is created in the SDK database based on the received data.

Anonymous Authentication

If your host app does not have its own authentication and you do not want to use phone-based authentication, you can use anonymous authentication. The SDK assigns a user ID without collecting a phone number.

await StreamLayer.useAnonymousAuth()

Managing Auth State

Remove the current user from the SDK and clear the user cache:

await StreamLayer.logout()

Query or observe the current auth state:

// Check whether the user is currently authorized
await StreamLayer.isUserAuthorized()

// Subscribe to auth-state updates
await StreamLayer.userIsAuthorizedState()

Related