happo-connect v1.0.5
Happo.js β The Official Social Login SDK for Happo
What is Happo.js?
Happo.js is a lightweight and easy-to-use JavaScript SDK that allows websites and applications to integrate Happo social login just like Facebook or Google OAuth.
With this, users can authenticate via Happo.gg and retrieve their account details securely without needing to create a separate login system.
πΉ No API keys required
πΉ Secure popup-based authentication
πΉ Simple event-driven approach
π Features
β
One-click authentication via Happo
β
Handles popup closures & errors automatically
β
Event-driven API (onConnect
, onError
)
β
Fully Promise-based for async/await support
π¦ Installation
Using a CDN (Recommended)
Simply include the following script in your HTML file:
<script src="https://www.happo.gg/connect/sdk.js"></script>
Via NPM
npm install happo-connect
Then import it in your project:
import Happo from "happo-connect"
π οΈ Usage
Quick Example
Happo.onConnect(user=>console.log("Connected as:",user))
Happo.onError(()=>console.log("Login failed or closed"))
Happo.connect().then(user=>{
console.log("User data received:",user)
}).catch(err=>{
console.error("Authentication failed:",err)
})
Advanced Example
For more control, you can handle login and display user details dynamically:
document.getElementById("login-btn").addEventListener("click",async()=>{
try{
const user=await Happo.connect()
document.getElementById("user-name").innerText=`Welcome, ${user.name}!`
}catch(err){
console.error("Failed to login:",err)
}
})
π§βπ» API Reference
Happo.connect(): Promise<User>
Opens the Happo authentication popup and returns a Promise with the logged-in userβs details.
Example
const user=await Happo.connect()
console.log(user.name) /// "Player1"
Returned User Object
Property | Type | Description |
---|---|---|
id | number | Unique user ID |
name | string | Userβs display name |
motto | string | User's bio/status |
email | string | Email (if permitted) |
figure | string | User's avatar figure |
club | boolean | Whether the user has Happo Club |
rank | number | User rank/level |
session | string | Session token for backend validation |
timestamp | number | Login timestamp |
Happo.onConnect(callback: (user: User) => void): void
Fires when a user successfully logs in. Provides the user object as an argument.
Example
Happo.onConnect(user=>{
console.log("User logged in:",user)
})
Happo.onError(callback: () => void): void
Fires when login fails (e.g., popup blocked, user closes it, or an error occurs).
Example
Happo.onError(()=>{
console.log("Login process was canceled or failed.")
})
π How It Works
Happo.connect()
opens a popup for authentication.- The user logs in via Happo.gg.
- Happo sends the userβs details securely via
window.postMessage()
. - The SDK captures the message, validates it, and resolves the Promise.
- You can access the userβs details in
onConnect()
or via the Promise response.
π Full Code Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Happo Login Demo</title>
</head>
<body>
<button id="login-btn">Connect with Happo</button>
<h2 id="user-name"></h2>
<script src="https://www.happo.gg/connect/sdk.js"></script>
<script>
document.getElementById("login-btn").addEventListener("click",async()=>{
try{
const user=await Happo.connect()
document.getElementById("user-name").innerText=`Welcome, ${user.name}!`
}catch(err){
console.error("Failed to login:",err)
}
})
</script>
</body>
</html>
π Why Use Happo.js?
β
No extra dependencies β Works out-of-the-box
β
Secure β Uses postMessage
& auto-closes popups
β
Event-driven β Listen for onConnect
& onError
β
Works with any front-end framework (React, Vue, Vanilla JS)
π License
MIT License Β© 2025 Happo.gg