To use the SDK, you must first create an API key in your Lemon Squeezy dashboard under Settings > API.
Security Warning: Do not use this package directly in the browser. Using it client-side will expose your API key, giving anyone full access to your Lemon Squeezy account and stores. This SDK is intended for server-side environments.
Initialize the SDK using lemonSqueezySetup by providing your apiKey and an optional onError handler.
import {
getAuthenticatedUser,
lemonSqueezySetup,
} from "@lemonsqueezy/lemonsqueezy.js";
const apiKey = import.meta.env.LEMON_SQUEEZY_API_KEY;
lemonSqueezySetup({
apiKey,
onError: (error) => console.error("Error!", error),
});
const { data, error } = await getAuthenticatedUser();
if (error) {
console.log(error.message);
} else {
console.log(data);
}