1.0.5 β€’ Published 5 months ago

happo-connect v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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

PropertyTypeDescription
idnumberUnique user ID
namestringUser’s display name
mottostringUser's bio/status
emailstringEmail (if permitted)
figurestringUser's avatar figure
clubbooleanWhether the user has Happo Club
ranknumberUser rank/level
sessionstringSession token for backend validation
timestampnumberLogin 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

  1. Happo.connect() opens a popup for authentication.
  2. The user logs in via Happo.gg.
  3. Happo sends the user’s details securely via window.postMessage().
  4. The SDK captures the message, validates it, and resolves the Promise.
  5. 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

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago