Server Side JavaScript SDK for Squadbase - A package for handling server-side operations in Squadbase applications.
npm install @squadbase/server
# or
yarn add @squadbase/server
# or
pnpm add @squadbase/serverUser info is automatically available in apps deployed to Squadbase or running in Squadbase Editor.
import { createServerClient } from "@squadbase/server";
const client = createServerClient({
cookieOptions: {
getCookie: () => {
// Implement your cookie retrieval logic here
// This should return the session cookie string
},
},
});
// Get the current authenticated user
const user = await client.getUser();
// {
// username: string,
// email: string,
// firstName: string,
// lastName: string,
// iconUrl: string | null,
// roles: string[]
// }For use outside Squadbase environments (e.g., local development), you must set the projectId and mockUser options. These settings are not needed in Squadbase Editor or deployed environments.
const client = createServerClient({
projectId: "your-project-id",
cookieOptions: {
getCookie: () => undefined,
},
mockUser: {
username: "test-user",
email: "test@example.com",
firstName: "Test",
lastName: "User",
iconUrl: null,
roles: ["user"],
},
});Creates a new server client instance.
projectId(optional): Your Squadbase project ID. Required outside Squadbase environments.cookieOptions(object):getCookie: Function that returns the session cookie string
mockUser(optional): Mock user object for use outside Squadbase environments
getUser(): Returns the current authenticated user- Returns: Promise
- Throws: Error if authentication fails
MIT