Get Started with ORGNET in 60 Seconds

Example 1: Protect a Web Page

Add the OrgNet SDK and protect your page with one line of code.

<!-- 1. Add the OrgNet SDK to your <head> -->
<script src="https://cdn.orgnet.app/v1/orgnet.min.js"></script>

<script>
  // 2. Configure your client
  const orgnet = new OrgNetClient({
    clientId: "YOUR_CLIENT_ID_FROM_DASHBOARD"
  });

  // 3. Protect the page. (Yes, that's it)
  // This automatically checks for a session and redirects to
  // your OrgNet login page if the user is not authenticated.
  orgnet.protectPage();
</script>

Example 2: Get User Profile Data

On a protected page, easily get the authenticated user's profile.

<!-- This assumes you've already configured orgnet (see Example 1) -->

<body>
  <h1>Welcome, <span id="username">Guest</span>!</h1>
</body>

<script>
  // Use an async function to get user data
  (async () => {
    
    // Wait for the SDK to be ready and check auth status
    if (await orgnet.isAuthenticated()) {
      
      // Get the user's profile object
      const user = await orgnet.getUser();
      
      // user object contains: { name: "...", email: "...", sub: "..." }
      document.getElementById("username").textContent = username;
    }
  
  })();
</script>