Auth
This module provides functionality to interact with authentication, enabling games to access user profiles, verify user authentication status, and manage the authentication flow with the parent site.
For detailed API documentation, refer to the user management section.
Interacting with the user profile involves:
Checking if a user is authorized; Reading user profile data from the server; Managing parent site authentication flows.
Supported Features
The Auth module integrates seamlessly with Arkadium's Game SDK, offering the following capabilities:
User Authentication Status - Determine whether the user is currently authenticated.
User Profile Access - Retrieve detailed user profile information.
Authentication UI - Interface with the parent site's authentication system.
Ensure proper handling of user data in compliance with privacy regulations.
Concepts
A User Profile includes essential information about the player, such as username, avatar, and other personalization details.
Checking User Authorization status helps in tailoring user experiences, such as saving game progress or enabling user-specific features.
The Authentication UI Manager facilitates interaction with the parent site's authentication flow, providing a seamless login experience.
Setup
To use the Auth module, initialize the SDK and access the userStateApi component
import * as ArkadiumApi from '@arkadiuminc/sdk';
const sdk = await ArkadiumApi.getInstance();
sdk.auth;
Every game should properly initialize the SDK to ensure access to user data and authentication features.
Managing Auth
Checking Authorization
Verify if the user is authorized:
const isAuthorized = await sdk.auth.isUserAuthorized();
if (isAuthorized) {
// User is authorized
}
Reading User Profile
Retrieve the user's profile data:
const profile = await sdk.auth.getUserProfile();
if (profile) {
console.log(profile.username);
}
This is the object structure returned by the API:
interface UserProfile {
uid: string;
username: string;
avatar: Image;
avatarFrame?: Image; // Eagle Arenas Only
avatarBackground?: string; // Eagle Arenas Only
isUserSubscriber: boolean;
aarpMembershipStatus?: boolean; // AARP Arena Only
coins?: number; // AARP Arena Only
level?: number; // AARP Arena Only
}
Subscribe to change of user auth status
sdk.auth.onAuthStatusChange((isAuthorized: boolean) => {
});
Managing Authentication UI
Opening the Authentication Form
Trigger the parent site's authentication form:
await sdk.auth.openAuthForm();
Subscribe to change of open Authentication Form
sdk.auth.onOpenAuthForm((isOpened: boolean) => {
});
Conclusion
The Auth module is essential for creating personalized and secure gaming experiences. Utilize this module to authenticate users, access profile information, and manage authentication flows efficiently.
To learn more about the various types of authenticated users, please view Registration States.