GlobioID - Authentication
GlobioID is Globio's authentication service. Secure user management with social logins, guest accounts, and cross-platform support.
🚀 Quick Start
import { GlobioID } from '@stanlink/globio'
const auth = new GlobioID({
apiKey: 'your-api-key',
projectId: 'your-project-id'
})
// Sign in with email/password
const user = await auth.signInWithEmailAndPassword('user@example.com', 'password')
console.log('Signed in:', user.uid)🔐 Authentication Methods
Email/Password
// Sign up
const user = await auth.createUserWithEmailAndPassword('user@example.com', 'password')
// Sign in
const user = await auth.signInWithEmailAndPassword('user@example.com', 'password')
// Sign out
await auth.signOut()Social Logins
// Google Sign-In
const user = await auth.signInWithGoogle()
// Apple Sign-In
const user = await auth.signInWithApple()
// Discord Sign-In (for gamers)
const user = await auth.signInWithDiscord()Guest Accounts
// Anonymous sign-in (perfect for games)
const guestUser = await auth.signInAnonymously()
console.log('Guest user:', guestUser.uid)
// Later, link to permanent account
await guestUser.linkWithEmailAndPassword('user@example.com', 'password')🎮 Gaming Authentication
Quick Game Start
// Let players start immediately
async function startGame() {
let user = auth.currentUser
if (!user) {
// Sign in anonymously for instant play
user = await auth.signInAnonymously()
}
// Load player data
const playerData = await loadPlayerData(user.uid)
startGameSession(playerData)
}Account Linking
// Link guest account to permanent account
async function upgradeGuestAccount() {
const currentUser = auth.currentUser
if (currentUser.isAnonymous) {
// Show account creation form
const email = prompt('Enter email to save your progress:')
const password = prompt('Create password:')
try {
await currentUser.linkWithEmailAndPassword(email, password)
console.log('Account upgraded! Progress saved.')
} catch (error) {
console.error('Failed to upgrade account:', error)
}
}
}Cross-Platform Sync
// Same account across devices
auth.onAuthStateChanged(async (user) => {
if (user) {
// Sync player data across devices
await syncPlayerData(user.uid)
console.log('Player data synced across devices')
}
})👤 User Management
User Profile
// Update user profile
await auth.currentUser.updateProfile({
displayName: 'PlayerName',
photoURL: 'https://example.com/avatar.jpg'
})
// Update email
await auth.currentUser.updateEmail('newemail@example.com')
// Update password
await auth.currentUser.updatePassword('newPassword')Custom Claims
// Set custom user data (server-side only)
await auth.setCustomUserClaims(userId, {
role: 'premium',
level: 50,
subscriptionTier: 'pro'
})
// Access custom claims
const token = await auth.currentUser.getIdToken()
const claims = parseJWT(token).claims
console.log('User role:', claims.role)🔒 Security Features
Email Verification
// Send verification email
await auth.currentUser.sendEmailVerification()
// Check if verified
if (auth.currentUser.emailVerified) {
console.log('Email is verified')
} else {
console.log('Please verify your email')
}Password Reset
// Send password reset email
await auth.sendPasswordResetEmail('user@example.com')Multi-Factor Authentication
// Enable 2FA
const multiFactorSession = await auth.currentUser.multiFactor.getSession()
const phoneAuthCredential = await verifyPhoneNumber('+1234567890')
await auth.currentUser.multiFactor.enroll(phoneAuthCredential, multiFactorSession)📱 Platform Examples
Unity C#
// Unity authentication
public async void SignInAnonymously() {
var user = await GlobioID.SignInAnonymouslyAsync();
Debug.Log($"Signed in as: {user.UserId}");
// Load player data
LoadPlayerData(user.UserId);
}
public async void LinkWithEmail(string email, string password) {
var currentUser = GlobioID.CurrentUser;
await currentUser.LinkWithEmailAndPasswordAsync(email, password);
Debug.Log("Account linked successfully!");
}Flutter/Dart
// Flutter authentication
Future<void> signInWithGoogle() async {
final user = await GlobioID.signInWithGoogle();
print('Signed in: ${user.uid}');
// Navigate to game
Navigator.pushReplacement(context, MaterialPageRoute(
builder: (context) => GameScreen(user: user)
));
}🎯 Best Practices
Error Handling
async function signIn(email, password) {
try {
const user = await auth.signInWithEmailAndPassword(email, password)
return { success: true, user }
} catch (error) {
switch (error.code) {
case 'auth/user-not-found':
return { success: false, message: 'No account found with this email' }
case 'auth/wrong-password':
return { success: false, message: 'Incorrect password' }
case 'auth/too-many-requests':
return { success: false, message: 'Too many failed attempts. Try again later.' }
default:
return { success: false, message: 'Sign in failed. Please try again.' }
}
}
}State Management
// Listen for auth state changes
auth.onAuthStateChanged((user) => {
if (user) {
// User signed in
console.log('User signed in:', user.uid)
loadUserData(user.uid)
} else {
// User signed out
console.log('User signed out')
clearUserData()
}
})Next: Learn about GlobalPulse Configuration →