> ## Documentation Index > Fetch the complete documentation index at: https://www.canva.dev/docs/apps/llms.txt > Use this file to discover all available pages before exploring further. # Using design IDs How to store and retrieve data against a user's design. Sometimes, apps need to associate data with a user's design. For example, an app could present the user with settings that persist on a per-design basis. To allow for this, apps can use the Canva Developers SDK to access the ID of the current design. **Warning:** If your app uses design IDs, we strongly encourage you to follow our [Security guidelines](https://www.canva.dev/#security-guidelines). ## Step 1: Get a design and user token For security reasons, Canva uses [JSON Web Tokens](https://datatracker.ietf.org/doc/html/rfc7519) (JWTs) to encode certain information. To access this information, apps must decode and verify the JWTs. In the Developers SDK, there are two types of tokens: * Design tokens * User tokens Design tokens encode information about the current design, such as the ID of the design, while user tokens encode information about the current user, such as the ID of the user and their team. Your app needs to use both tokens to securely store data against a user's design. To get a user token: 1. Import the `auth` constant from the `@canva/user` package: ```tsx import { auth } from "@canva/user"; ``` 2. Call the `getCanvaUserToken` method: ```tsx const userToken = await auth.getCanvaUserToken(); ``` To get a design token: 1. Import the `getDesignToken` method from the `@canva/design` package: ```tsx import { getDesignToken } from "@canva/design"; ``` 2. Call the `getDesignToken` method: ```tsx const designToken = await getDesignToken(); ``` ## Step 2: Send the tokens to the app's backend For security reasons, apps must decode and verify tokens through their backend — never through the frontend. In the same request, the app should also send whatever data it wants to store against the user's design, such as any settings the user has configured through the app's frontend. The shape of this data is highly dependent on the behavior of the app and isn't specific to the Developers SDK, so it's not demonstrated here. The following code snippet demonstrates how an app can send tokens to a backend: ```tsx const response = await fetch( `http://localhost:3001/my/api/endpoint?designToken=${designToken}`, { method: "POST", headers: { Authorization: `Bearer ${userToken}`, }, } ); ``` In this case, the design token is sent as a query parameter, but this isn't a strict requirement. You could send the token in some other way, such as in the body of a `POST` request. The user token must always be sent as an `Authorization` header. Learn more about [HTTP request verification](https://www.canva.dev/docs/apps/verifying-http-requests/). ## Step 3: Verify the tokens After the backend receives the tokens, it must decode and verify them before it can access the encoded data. For a step-by-step walkthrough of how to do this, see [JSON Web Tokens](https://www.canva.dev/docs/apps/verifying-jwts/). **For Node.js backends:** We recommend using the [`@canva/app-middleware`](https://www.npmjs.com/package/@canva/app-middleware) package, which provides built-in JWT verification, JWKS caching, and error handling. This package simplifies the verification process and follows security best practices. ### Installation ```shell npm install @canva/app-middleware ``` ### Express.js middleware For Express.js applications, use the built-in middleware: ```typescript import express from "express"; import { design, tokenExtractors } from "@canva/app-middleware/express"; const app = express(); // Design token middleware requires explicit token extraction app.post( "/my/api/design", design.verifyToken({ appId: process.env.CANVA_APP_ID, tokenExtractor: tokenExtractors.fromQuery("designToken"), }), (req, res) => { // Access verified design information const { designId, appId } = req.canva.design; // Your application logic here res.sendStatus(200); } ); app.listen(process.env.PORT || 3000); ``` NOTE: Design tokens require an explicit `tokenExtractor` parameter. The available extractors are `tokenExtractors.fromQuery()`, `tokenExtractors.fromCookie()`, and `tokenExtractors.fromBearerAuth()`. ### Framework-agnostic function For other Node.js environments (Next.js, AWS Lambda, Cloudflare Workers, and so on): ## Manually verifying JWTs If you're using a non-Node.js backend, you can manually verify JWTs. The following steps show how to implement JWT verification from scratch in TypeScript, which you can then adapt to your preferred language or framework. ### Step 4: Verify the tokens Use the public key to verify both the user token and design token: ```ts const verifiedUserToken = jwt.verify("USER_JWT_GOES_HERE", publicKey, { audience: "YOUR_APP_ID", }); const verifiedDesignToken = jwt.verify("DESIGN_JWT_GOES_HERE", publicKey, { audience: "YOUR_APP_ID", }); ``` The exact syntax will depend on the library you're using. If the tokens are valid, the verified tokens will be dictionaries. The user token will contain the following properties: * `aud` - The ID of the app. * `brandId` - The ID of the user's team. * `userId` - The ID of the user. The design token will contain the following properties: * `aud` - The ID of the app. * `designId` - The ID of the current design. If these properties aren't available, it means the tokens or public key are invalid: ```tsx if (!verifiedUserToken.aud || !verifiedUserToken.brandId || !verifiedUserToken.userId) { throw new Error("The user token is not valid"); } if (!verifiedDesignToken.aud || !verifiedDesignToken.designId) { throw new Error("The design token is not valid"); } ``` ## Step 4: Store data against the design After the app's backend verifies the tokens, it will have access to: * The ID of the design * The ID of the user * The ID of the user's team The backend can then use the combination of these properties to store data that's linked to the design. The key word here is *combination*, as it's important to note that: * A design may have multiple users collaborating on it. * A user may belong to multiple teams. Therefore, any data shouldn't only be linked with the ID of the design, as this would allow data to be leaked between users or between teams. The data should be linked with the ID of the design, the user, and the user's team. This means a database table containing data linked to a design would likely have the following columns: * `design_id` * `team_id` But the exact implementation details may be different. ## Step 5: Retrieve data for the design To retrieve data linked with a design, repeat the previous steps but for an endpoint that performs a read operation instead of a write operation. Be sure the data is scoped to the ID of the design, the user, and the user's team. ## Security guidelines To ensure that data is always linked with the correct design, user, and team, follow these guidelines: * Decode and verify tokens through the backend. Your app should never attempt to decode and verify tokens through its frontend. To learn more, see [JSON Web Tokens](https://www.canva.dev/docs/apps/verifying-jwts/). * Get fresh tokens from Canva before sending the tokens to the app's backend. Don't attempt to cache or reuse tokens across multiple HTTP requests. * Send tokens to an app's backend with any data relevant to the request, such as data required to perform a read or write operation related to a particular design. Don't send tokens and relevant data in separate requests. The following code sample demonstrates what these guidelines look like in practice: ```tsx import { auth } from "@canva/user"; import { getDesignToken } from "@canva/design"; // Get fresh tokens before every request const designToken = await getDesignToken(); const userToken = await auth.getCanvaUserToken(); // Send tokens to the app's backend const response = await fetch( `http://localhost:3001/my/api/endpoint?designToken=${designToken}`, { method: "POST", headers: { Authorization: `Bearer ${userToken}`, "Content-Type": "application/json", }, // Include relevant data in the same request as the tokens body: JSON.stringify({ name: "David", age: 33, location: "Australia", }), } ); ```