diff --git a/docs/docs/01-getting-started/02-setup.md b/docs/docs/01-getting-started/02-setup.md index f62983dbd..887955877 100644 --- a/docs/docs/01-getting-started/02-setup.md +++ b/docs/docs/01-getting-started/02-setup.md @@ -53,14 +53,15 @@ npm install @stackframe/stack STACK_SECRET_SERVER_KEY= ``` -2. Create a new file in `lib/stack.ts` and fill it with the following: +2. Create a new file `stack.ts` in your root directory and fill it with the following: ```tsx import "server-only"; import { StackServerApp } from "@stackframe/stack"; - export const stackApp = new StackServerApp({ + export const stackServerApp = new StackServerApp({ tokenStore: "nextjs-cookie", // storing auth tokens in cookies + //there is other parameter named "urls" which is covered later in the docs }); ``` @@ -72,10 +73,10 @@ npm install @stackframe/stack ```tsx import { StackHandler } from "@stackframe/stack"; - import { stackApp } from "@/lib/stack"; + import { stackServerApp } from "@/stack"; export default function Handler(props: any) { - return ; + return ; } ``` @@ -87,13 +88,13 @@ npm install @stackframe/stack ```tsx import React from "react"; import { StackProvider, StackTheme } from "@stackframe/stack"; - import { stackApp } from "@/lib/stack"; + import { stackServerApp } from "@/stack"; export default function RootLayout({ children }: { children: React.ReactNode }) { return ( - + {children} diff --git a/docs/docs/01-getting-started/03-users.md b/docs/docs/01-getting-started/03-users.md index 58bcdc51e..fa1d18831 100644 --- a/docs/docs/01-getting-started/03-users.md +++ b/docs/docs/01-getting-started/03-users.md @@ -33,10 +33,10 @@ On Server Components, you don't need `useStackApp()`. Instead, you can just impo ```tsx import "server-only"; -import { stackApp } from "@/lib/stack"; +import { stackServerApp } from "@/stack"; export default async function MyComponent() { - const user = await stackApp.getUser(); + const user = await stackServerApp.getUser(); return
{user ? `Hello, ${user.displayName ?? "anon"}` : 'You are not logged in'}
; } @@ -68,10 +68,10 @@ Call `useUser` (or `getUser`) with the `{ or: 'redirect' }` option to protect th ```tsx - import { stackApp } from "@/lib/stack"; + import { stackServerApp } from "@/stack"; export default async function Protected() { - await stackApp.getUser({ or: 'redirect' }); + await stackServerApp.getUser({ or: 'redirect' }); return

You can only see this if you are logged in

} ``` @@ -101,10 +101,10 @@ You can sign out the user by redirecting them to `/handler/signout` or simply by ```tsx - import { stackApp } from "@/lib/stack"; + import { stackServerApp } from "@/stack"; export default async function SignOutLink() { - return + return Sign Out ; } @@ -150,11 +150,11 @@ Stack automatically creates a user profile on sign-up. Let's create a page that ```tsx - import { stackApp } from "@/lib/stack"; + import { stackServerApp } from "@/stack"; import { UserButton } from "@stackframe/stack"; export default async function Page() { - const user = await stackApp.getUser(); + const user = await stackServerApp.getUser(); return (
{user ? ( @@ -162,13 +162,13 @@ Stack automatically creates a user profile on sign-up. Let's create a page that

Welcome, {user.displayName}

Your e-mail: {user.primaryEmail}

-

Sign Out

+

Sign Out

) : (

You are not logged in

-

Sign in

-

Sign up

+

Sign in

+

Sign up

)} @@ -223,8 +223,8 @@ If you want to store sensitive information that is only visible on the server si ```tsx // server side only -import { stackApp } from "@/lib/stack"; -const user = await stackApp.getUser(); +import { stackServerApp } from "@/stack"; +const user = await stackServerApp.getUser(); await user.update({ serverMetadata: { secretInfo: "This is a secret", @@ -236,8 +236,8 @@ You can also access them from the `User` object: ```tsx // server side only -import { stackApp } from "@/lib/stack"; -const user = await stackApp.getUser(); +import { stackServerApp } from "@/stack"; +const user = await stackServerApp.getUser(); console.log(user.serverMetadata); ``` diff --git a/docs/docs/01-getting-started/04-teams.md b/docs/docs/01-getting-started/04-teams.md index 2790e3401..b8a03fc8e 100644 --- a/docs/docs/01-getting-started/04-teams.md +++ b/docs/docs/01-getting-started/04-teams.md @@ -56,10 +56,10 @@ You can list all the teams a user belongs to by using the `listTeams` method or ```tsx - import { stackApp } from "@/lib/stack"; + import { stackServerApp } from "@/stack"; export default async function DisplayUserTeams() { - const user = await stackApp.getUser({ or: 'redirect' }); + const user = await stackServerApp.getUser({ or: 'redirect' }); const teams = await user.listTeams(); return
@@ -94,10 +94,10 @@ To obtain details of a specific team that a user belongs to, use the `getTeam` m ```tsx - import { stackApp } from "@/lib/stack"; + import { stackServerApp } from "@/stack"; export default async function DisplayUserTeam(props: { teamId: string }) { - const user = await stackApp.getUser({ or: 'redirect' }); + const user = await stackServerApp.getUser({ or: 'redirect' }); const team = await user.getTeam(props.teamId); return
@@ -182,10 +182,10 @@ You can check if a user has a specific permission by using the `getPermission` m ```tsx - import { stackApp } from "@/lib/stack"; + import { stackServerApp } from "@/stack"; export default async function CheckUserPermission() { - const user = await stackApp.getUser({ or: 'redirect' }); + const user = await stackServerApp.getUser({ or: 'redirect' }); const permission = await user.getPermission('read'); // This is a server side check, so it's secure @@ -221,10 +221,10 @@ To get all permissions a user has, use the `listPermissions` method or `usePermi ```tsx - import { stackApp } from "@/lib/stack"; + import { stackServerApp } from "@/stack"; export default async function DisplayUserPermissions() { - const user = await stackApp.getUser({ or: 'redirect' }); + const user = await stackServerApp.getUser({ or: 'redirect' }); const permissions = await user.listPermissions(); return
diff --git a/docs/docs/02-customization/04-custom-pages.md b/docs/docs/02-customization/04-custom-pages.md index 1ef447ad5..c4b909a96 100644 --- a/docs/docs/02-customization/04-custom-pages.md +++ b/docs/docs/02-customization/04-custom-pages.md @@ -21,10 +21,10 @@ export default function CustomSignInPage() { } ``` -Then you can instruct the Stack app in `lib/stack.ts` to use your custom sign in page: +Then you can instruct the Stack app in `stack.ts` to use your custom sign in page: ```tsx -export const stackApp = new StackServerApp({ +export const stackServerApp = new StackServerApp({ // ... // add these three lines urls: { @@ -61,10 +61,10 @@ export default function CustomOAuthSignIn() { } ``` -Again, edit the Stack app in `lib/stack.ts` to use your custom sign in page: +Again, edit the Stack app in `stack.ts` to use your custom sign in page: ```tsx -export const stackApp = new StackServerApp({ +export const stackServerApp = new StackServerApp({ // ... // add these three lines urls: { diff --git a/docs/docs/03-api-documentation/01-user.md b/docs/docs/03-api-documentation/01-user.md index 42ffd23d3..7ac553145 100644 --- a/docs/docs/03-api-documentation/01-user.md +++ b/docs/docs/03-api-documentation/01-user.md @@ -10,7 +10,7 @@ sidebar_position: 1 ## `CurrentUser` Object -You can call `useUser()` or `stackApp.getUser()` to get the `CurrentUser` object. +You can call `useUser()` or `stackServerApp.getUser()` to get the `CurrentUser` object. ### Attributes @@ -82,7 +82,7 @@ if (error) { ## `CurrentServerUser` Object -You can call `stackApp.getServerUser()` to get the `CurrentServerUser` object. `CurrentServerUser` has all the attributes and methods of `CurrentUser` and some additional ones shown below. +You can call `stackServerApp.getServerUser()` to get the `CurrentServerUser` object. `CurrentServerUser` has all the attributes and methods of `CurrentUser` and some additional ones shown below. Note the `CurrentServerUser` should only be used on the server side because it contains server only metadata. diff --git a/docs/docs/03-api-documentation/03-app.md b/docs/docs/03-api-documentation/03-app.md index ce08cc257..3ecd64d5f 100644 --- a/docs/docs/03-api-documentation/03-app.md +++ b/docs/docs/03-api-documentation/03-app.md @@ -12,13 +12,13 @@ sidebar_position: 1 ## Initialization -We showed in the [setup guide](../01-getting-started/02-setup.md) that you can create a `StackServerApp` in a file like `lib/stack.ts` like this: +We showed in the [setup guide](../01-getting-started/02-setup.md) that you can create a `StackServerApp` in a file like `stack.ts` like this: ```tsx import "server-only"; import { StackServerApp } from "@stackframe/stack"; -export const stackApp = new StackServerApp({ +export const stackServerApp = new StackServerApp({ tokenStore: "nextjs-cookie", // storing auth tokens in cookies }); ``` @@ -32,7 +32,7 @@ An object that contains some pre-defined URLs that Stack uses to route and redir Example: ```tsx -export const stackApp = new StackServerApp({ +export const stackServerApp = new StackServerApp({ tokenStore: "nextjs-cookie", urls: { signIn: "/custom-sign-in",