This is a starter template for Storyblok Space Plugins, created with Next.js (Pages Router) and @storyblok/app-extension-auth.
WARNING: App Bridge should be activated in the Extension for this template to work.
npx giget@latest gh:storyblok/space-tool-plugins/space-plugins/nextjs-starter YOUR-PROJECT-NAMENavigate to your project folder and install dependencies by running:
cd YOUR-PROJECT-NAME
pnpm install # yarn install or npm installSet up a secure tunnel to proxy your request to/from localhost:3000, for example, with ngrok:
ngrok http 3000Note down your assigned URL; this will be your baseUrl for the application.
There are two ways on how you can create a Space Plugin inside Storyblok. Depending on your plan and use case, choose one of the following options:
- Open Storyblok's Partner Portal Extension View
- Click On New Extension
- Fill in the fields
nameandslug - Select
Sidebaras extension type - Click on Save
- Open Storyblok's Organization Extension View
- Click On New Extension
- Fill in the fields
nameandslug - Select
Sidebaras extension type - Click on Save
Once the extension has been created, a new entry will appear inside the extension list. Open it and navigate to the OAuth 2.0 and Pages tab.
Configure the following properties based on the previous steps:
- Index to your page:
{baseUrl} - Redirection endpoint:
{baseUrl}/api/connect/callback
Rename the file .env.local.example to .env.local. Open the file and set the environmental variables:
CLIENT_ID: the client ID from the extension's settings page.CLIENT_SECRET: the client secret from the extension's settings page.BASE_URL: ThebaseUrlfrom your secure tunnel.
Start the application by running:
pnpm dev # yarn dev or npm run devApp Bridge is an extra authentication layer recently introduced for Space Plugins and Tool Plugins. This starter assumes you've enabled App Bridge on the Settings page. Documentation on App Bridge will come in the near future, but you don't need to know about its inner process. This starter addresses a large portion of this aspect out of the box.
If you don't want to use App Bridge, you can use the legacy template.
App Bridge authentication starts on the frontend by sending a postMessage to app.storyblok.com. In the src/pages/index.tsx file, you can find the following code:
const { completed } = useAppBridge({ type: 'space-plugin', oauth: true });
return (
<div>
{completed && (
<div>
<UserInfo />
<Example />
</div>
)}
</div>
);The code above handles both App Bridge authentication and OAuth.
- If you need to use Storyblok's Management API:
After completing both authentications, the <UserInfo /> component is rendered. This component sends a request to /api/user_info. The OAuth token is automatically included in the request as a cookie, and the endpoint retrieves the session using await getAppSession(req, res). It then fetches user information from Storyblok's Management API using the OAuth token.
- If you don't need the Management API but still want to validate the request on the backend:
When the <Example /> component is rendered, it makes a request to /api/example. We attach the App Bridge token as a header. The endpoint verifies the token using await verifyAppBridgeHeader(req). Only if the token is verified can you perform any desired action.
Finally, install the application to your space:
- Navigate to the extension's settings page.
- Open the General Tab.
- Open the Install Link in a new browser tab.
- Select a space the Space Plugin should be installed to.
- Open the selected space from Step 4.
- Click
Apps > <Your Extension Name>on the sidebar.
The installation process is only done once per space. After the installation is finished, you will be able to navigate to the Apps section on the sidebar and access the Space Plugin.
When deploying your Space Plugin, please remember to adjust the extension settings inside the Storyblok App to point to the correct Index to your page and Redirection endpoint.
For more detailed information on Storyblok extensions, read the following guides:
If you have trouble setting up the development environment, please review the following:
-
Ensure that the
.env.localfile is correctly set up with the following variables:CLIENT_ID=CLIENT_SECRET=BASE_URL=
-
Ensure that the tunnel is correctly set up with the
BASE_URL. -
Ensure that the extension settings inside Storyblok are correctly set up with the following properties:
- Index to your page:
{BASE_URL} - Redirection endpoint:
{BASE_URL}/api/connect/callback
- Index to your page:
- Ensure that the extension settings inside Storyblok have the "Use App Bridge" option enabled.
- Ensure that the ad-blocker browser extensions are disabled when developing the extension.

