gatekeeper-core
v1.0.0
Published
This package contains the utilities for Google OAuth
Downloads
15
Maintainers
Readme
🔐 Gatekeeper Auth SDK
A lightweight JavaScript SDK for integrating Google OAuth authentication via Gatekeeper. Built for React apps, this SDK simplifies login/signup flows, token handling, and user data retrieval.
🚀 Features
- Google OAuth login via Gatekeeper
- Automatic token parsing from URL
- User data fetching and caching
- React hook for easy integration
- Namespaced
localStoragekeys (gatekeeper_*)
📦 Installation
npm install gatekeeper-auth-sdk
🧩 Usage
1. Initialize the SDK
Call initAuth() once with your Gatekeeper access key.
js
import { initAuth } from 'gatekeeper-auth-sdk';
initAuth('your-access-key');
2. Trigger Google Login
Redirects the user to Google OAuth via Gatekeeper.
js
import { googleAuth } from 'gatekeeper-auth-sdk';
googleAuth(); // Automatically redirects
3. Use the React Hook
After redirect, use useUserData() to access the authenticated user.
js
import { useUserData } from 'gatekeeper-auth-sdk';
function Dashboard() {
const { data, status, message, error, isLoading } = useUserData();
if (isLoading) return <p>Loading...</p>;
if (error) return <p>Error: {error}</p>;
return (
<div>
<h2>{message}</h2>
<pre>{JSON.stringify(data, null, 2)}</pre>
</div>
);
}🧠 API Reference
initAuth(accessKey: string): void
// Stores your Gatekeeper access key for future use.
googleAuth(): Promise<void>
Redirects the user to Google OAuth via Gatekeeper.
useUserData(): { data, status, message, error, isLoading }
React hook that:
Parses the URL hash after redirect
Stores token and metadata
Fetches user data from Gatekeeper
Caches it in localStorage🗂 LocalStorage Keys Used
Key Purpose
gatekeeper_token -> Stores the handoff token from Gatekeeper
gatekeeper_user -> Stores fetched user data
