Live Auth
RelayBox "Live Auth" authentication service provides a robust, real-time solution for managing user authentication with ease. Whether you're setting up traditional password-based login, OAuth integration, or tracking user presence, RelayBox ensures a secure and scalable system.
Click here to view the full Live Auth technical documentation
With features like key-based security, live and multi-factor authentication and secure token lifecycle management you can quickly implement and manage user access and interaction while maintaining full control over authentication workflows.
Getting started with Live Auth
Getting started with Live Auth is straightforward. First up, Follow these steps to create an API key for your application.
Your API key should look something like this...
Fef8GnS7C5zN.GFVHaIrJ6Y1_:cc3c675ca0e7f798404efa441f14d58ae56db3d3a1cfcf89451fdaae7a68bd53
__________________________________________________________________________________________
| Public key | Secret Key |
To use live auth, we need to extract the public key from the API key. The public key is the first part of the API key separated by a colon.
If we take the example above, the public key would be...
Fef8GnS7C5zN.GFVHaIrJ6Y1_
Connecting an application
We can use the public key to interact with the Live Auth service. If you haven't already done so, go ahead and install the RelayBox client library SDK in your client-side application
cd my-app
npm install @relaybox/client
Once installed, simply initialize a new RelayBox instance with public key.
const relayBox = new RelayBox({
publicKey: 'Fef8GnS7C5zN.GFVHaIrJ6Y1_'
});
We're now ready to start interacting with the Live Auth service. Let's start by creating a new user account using a traditional password-based flow.
const response = await relayBox.auth.signUp({
email: 'hello@universe.com',
password: 'my-super-secure-password'
});
A 6 digit code will be sent to the email address used during registration. The new user will need to verify they own that email address before they can continue to authenticate.
const result = await relayBox.auth.verify({ email, code });
If verification is successful, the user will then be able to authenticate using their new login credentials.
const authUserSession = await relayBox.auth.signIn({ email, password });
// Elsewhere in your application...
relayBox.auth.onAuthEvent('SIGN_IN', async (session: any) => {
console.log(session);
})
Users and sessions
After a successful authentication, a session will be available containing a signed auth token that can be used to gain access to realtime services, add user data to events, metrics and presence sets. The Client SDK library manages the auth token lifecycle and refresh mechanism automatically.
For more information about auth tokens, sessions and application security preferences, please refer to the Auth Tokens and API Keys documentation.
Users within the application can subscribe to other users to recieve realtime events such as connection and status updates.
const user = await relayBox.auth.getUser({ clientId });
user.onConnectionEvent((data: any) => {
const { isOnline, lastOnline } = data;
console.log(`${user.username} is ${isOnline ? 'online' : 'offline'}`);
});
user.onStatusUpdate((data: any) => {
const { status, updatedAt } = data;
console.log(data);
});
RelayBox Live Auth is a powerful authentication service that can be used to manage realtime connections and users in your applications or used in conjunction with @relaybox/rest to lock down your own backend systems.