Authentication
@preternatural-js/client-sdk instance references a Preternatural Customer.
Get Customer’s current authentication Credentials
Read the current session with getAuthData():
const session = client.getAuthData()
if (session) {
saveCustomerSession(session)
}Set or Replace Customer Authentication Credentials
client.setState({
accessToken: 'customer-access-token',
refreshToken: 'customer-refresh-token',
customerId: 'customer-id',
projectId: 'project-id',
sandboxMode: false
})Replacing the session stops streams created by the previous customer.
Authenticate a synthetic sandbox customer
Create a synthetic customer in the Preternatural dashboard, then authenticate it with its customer secret:
const client = createCustomerClient({
environment: 'production',
projectId: 'sandbox-project-id',
sandboxMode: true
})
await client.authenticateWithCustomerSecret(
'sandbox-customer-secret'
)WARNING
TODO: check whether customer secret is exposed and copyable by the project admin from the modem-app dashboard MODEM-921
The SDK exchanges the secret for customer access and refresh tokens.
Refresh the access token
await client.refreshSession()
const updatedSession = client.getAuthData()refreshSession() uses the stored refresh token and updates the client with the new access token.
Handling authentication with external identity providers
NOTE
OUT OF SCOPE : Integration with external auth providers like Clerk and Firebase is out of scope for this ticket