This package is designed to allow Whop Apps to interact with the Whop OAuth component that lives at https://oauth.api.whop.com
. It exports both helper functions and an API wrapper to make calls to the REST API.
"use client";
import { initOauth } from "@whop-apps/sdk";
export const Component = () => {
const handleGoogleLogin = useCallback(() => {
initOAuth({
provider: "google",
scope: "profile email openid",
restPath: "/oauth_callback",
});
}, []);
return (
<div>
<button onClick={handleGoogleLogin}>Login</button>
</div>
);
}
import { OAuthApi } from "@whop-apps/sdk";
// Retrieve an access token based on a profile ID and user ID
const accessToken = await OAuthApi({ mode: "server" }).retrieveToken({
profile_id: "google_xxxxxxxxx",
provider: "google",
user_id: "user_xxxxxxxxx",
}).then((t) => t.access_token);
// Upload your credentials to the Whop OAuth API
await OAuthApi({ mode: "server" }).createCredentials({
client_id: "YOUR_CLIENT_ID_HERE",
client_secret: "YOUR_CLIENT_SECRET_HERE",
provider: "google"
});
// List all profiles the user has for a specific platform
const profiles = await OAuthApi({ mode: "server" }).listProfiles({
provider: "google",
user_id: "user_xxxxxxxxx",
});