Authentication Forwarding
The StreamLayer SDK providers rich set of the features. Some of them requires user authentication. The SDK provides several ways how to authenticate user so you can decide which one is better for you particular app. Let's overview all of them.
Bypass Authentication
If your host app has already been authenticated with the token verification system, you can forward that authentication token to the StreamLayer SDK. By doing so, your users won't need to authenticate repeatedly in our SDK - they will be automatically authenticated instead.
To enable authentication call use the following StreamLayerLogin:
schema
- your authorization scheme that you provide to ustoken
- your authorization token
import { StreamLayerProvider } from '@streamlayer/react'
import { StreamLayerLogin } from '@streamlayer/react/auth'
...
<StreamLayerProvider {...providerProps}>
// You can place the StreamLayerLogin component wherever you want in your app,
// but it should be wrapped inside the StreamLayerProvider component.
<StreamLayerLogin token={token} schema={schema} />
</StreamLayerProvider>
...
Anonymous Authentication
If you don't have any authentication system, you can use anonymous authentication.
Install plugin
npm install @streamlayer/sdk-web-anonymous-auth
import { StreamLayerProvider, useStreamLayer } from '@streamlayer/react'
import { anonymous } from '@streamlayer/sdk-web-anonymous-auth'
const plugins = new Set([anonymous])
const Login = () => {
const sdk = useStreamLayer()
useEffect(() => {
sdk?.anonymousAuthorization()
}, [sdk])
return null
}
const App = () => {
return (
<StreamLayerProvider {...providerProps} plugins={plugins}>
// You can place the StreamLayerLogin component wherever you want in your app,
// but it should be wrapped inside the StreamLayerProvider component.
<Login />
</StreamLayerProvider>
)
}