--- title: StackServerApp subtitle: Reference for the StackServerApp object (server-side) enableTableOfContents: true tag: beta --- `StackServerApp` is the main object for interacting with Stack Auth on the server. It provides methods for authentication, user management, and team management with full server permissions. > **Note:** Only use `StackServerApp` in trusted server environments. It requires your `SECRET_SERVER_KEY`. ## Table of Contents
type{" "}StackServerApp = {'{'}
new(options): StackServerApp;

getUser([id], [options]): Promise<ServerUser|null>;
useUser([id], [options]): ServerUser;
listUsers([options]): Promise<ServerUser[]>;
useUsers([options]): ServerUser[];
createUser([options]): Promise<ServerUser>;

getTeam(id): Promise<ServerTeam|null>;
useTeam(id): ServerTeam;
listTeams(): Promise<ServerTeam[]>;
useTeams(): ServerTeam[];
createTeam([options]): Promise<ServerTeam>;
{"};"}
## Constructor Creates a new `StackServerApp` instance. ### Parameters - `tokenStore`: The token store to use. Can be one of: - `"nextjs-cookie"`: Uses Next.js cookies (recommended for Next.js apps) - `"cookie"`: Uses browser cookies - `{ accessToken: string, refreshToken: string }`: Uses provided tokens - `Request`: Uses the provided request object - `secretServerKey`: The secret server key for your app. - `baseUrl`, `projectId`, `publishableClientKey`, `urls`, `noAutomaticPrefetch`: (see [StackClientApp](/docs/neon-auth/sdk/nextjs/objects/stack-app#constructor) for details) ### Signature ```typescript declare new(options: { tokenStore: "nextjs-cookie" | "cookie" | { accessToken: string, refreshToken: string } | Request; secretServerKey?: string; baseUrl?: string; projectId?: string; publishableClientKey?: string; urls: { signIn: string; signUp?: string; forgotPassword?: string; }; noAutomaticPrefetch?: boolean; }): StackServerApp; ``` ### Example ```typescript const stackServerApp = new StackServerApp({ tokenStore: 'nextjs-cookie', secretServerKey: process.env.SECRET_SERVER_KEY, urls: { signIn: '/my-custom-sign-in-page' }, }); ``` ## Methods ## `stackServerApp.getUser([id], [options])` (#getuser) Returns a `ServerUser` by ID, or the current user if no ID is provided. ### Parameters (#getuser-parameters) - `id` (string, optional): The user ID. - `options` (object, optional): `{ or?: "return-null" | "redirect" | "throw" }` ### Returns (#getuser-returns) `Promise` ### Example (#getuser-example) ```typescript const user = await stackServerApp.getUser('user_id'); ``` ## `stackServerApp.useUser([id], [options])` (#useuser) Functionally equivalent to `getUser([id], [options])`, but as a React hook. ### Parameters (#useuser-parameters) - `id` (string, optional): The user ID. - `options` (object, optional): `{ or?: "return-null" | "redirect" | "throw" }` ### Returns (#useuser-returns) `ServerUser` ### Example (#useuser-example) ```typescript const user = await stackServerApp.useUser('user_id'); ``` ## `stackServerApp.listUsers([options])` (#listusers) Lists all users on the project. ### Parameters (#listusers-parameters) - `options` (object, optional): - `cursor` (string): The cursor to start from. - `limit` (number): Max number of users to return. - `orderBy` (string): Field to sort by (`"signedUpAt"`). - `desc` (boolean): Sort descending. - `query` (string): Free-text search. ### Returns (#listusers-returns) `Promise` (with `nextCursor` property) ### Example (#listusers-example) ```typescript const users = await stackServerApp.listUsers({ limit: 20 }); ``` ## `stackServerApp.useUsers([options])` (#useusers) Functionally equivalent to `listUsers([options])`, but as a React hook. ### Parameters (#useusers-parameters) - `options` (object, optional): - `cursor` (string): The cursor to start from. - `limit` (number): Max number of users to return. - `orderBy` (string): Field to sort by (`"signedUpAt"`). - `desc` (boolean): Sort descending. - `query` (string): Free-text search. ### Returns (#useusers-returns) `ServerUser[]` ### Example (#useusers-example) ```typescript const users = await stackServerApp.useUsers({ limit: 20 }); ``` ## `stackServerApp.createUser([options])` (#createuser) Creates a new user from the server. ### Parameters (#createuser-parameters) - `options` (object): - `primaryEmail` (string) - `primaryEmailVerified` (boolean) - `primaryEmailAuthEnabled` (boolean) - `password` (string) - `otpAuthEnabled` (boolean) - `displayName` (string) ### Returns (#createuser-returns) `Promise` ### Example (#createuser-example) ```typescript const user = await stackServerApp.createUser({ primaryEmail: 'test@example.com', primaryEmailAuthEnabled: true, password: 'password123', }); ``` ## `stackServerApp.getTeam(id)` (#getteam) Gets a team by its ID. ### Parameters (#getteam-parameters) - `id` (string): The team ID. ### Returns (#getteam-returns) `Promise` ### Example (#getteam-example) ```typescript const team = await stackServerApp.getTeam('team_id'); ``` ## `stackServerApp.useTeam(id)` (#useteam) Functionally equivalent to `getTeam(id)`, but as a React hook. ### Parameters (#useteam-parameters) - `id` (string): The team ID. ### Returns (#useteam-returns) `ServerTeam` ### Example (#useteam-example) ```typescript const team = stackServerApp.useTeam('team_id'); ``` ## `stackServerApp.listTeams()` (#listteams) Lists all teams on the current project. ### Returns (#listteams-returns) `Promise` ### Example (#listteams-example) ```typescript const teams = await stackServerApp.listTeams(); ``` ## `stackServerApp.useTeams()` (#useteams) Functionally equivalent to `listTeams()`, but as a React hook. ### Returns (#useteams-returns) `ServerTeam[]` ### Example (#useteams-example) ```typescript const teams = stackServerApp.useTeams(); ``` ## `stackServerApp.createTeam([options])` (#createteam) Creates a team. ### Parameters (#createteam-parameters) - `options` (object): - `displayName` (string): The display name for the team. - `profileImageUrl` (string | null): The URL of the team's profile image, or null to remove. ### Returns (#createteam-returns) `Promise` ### Example (#createteam-example) ```typescript const team = await stackServerApp.createTeam({ displayName: 'New Team', profileImageUrl: 'https://example.com/profile.jpg', }); ```