Appwrite Ssr Svelte Kit

Appwrite Loves Svelte Kit! Demo application with authorized server-side and client-side rendering.

Almost SSR - Svelte Kit

Demo application with authorized server-side and client-side rendering.

πŸ‘€ Looking for Different Framework?

πŸ’­ So How Does It Work?

Appwrite uses 1st party secure cookies for authorization. For legacy reasons, there are two such cookies. They are both very similar, but one's name ends with _legacy and is configured a tiny bit differently. It's also possible to use a fallback cookie, but that is not secure for production, and we will not be using that.

To ensure server-side rendering works, we need to set those cookies on our SSR server hostname instead of the Appwrite hostname. Let's say our Appwrite instance is on, and our app is on SSR server on domain won't receive cookies. This is expected behavior, as browsers keep 1st party cookies securely scoped to specific domains.

To set those cookies on the SSR server, we need a special API endpoint in our SSR server. This endpoint will send a request to create a session, proxying email/password or other credentials. This endpoint next parses the response set-cookie header, replaces domain configuration on the cookies, and set's it's own set-cookie on the response to the client.

When a client calls this endpoint, the cookie will now be set on the SSR server hostname instead of the Appwrite hostname.

This makes server-side rendering work, but now client-side rendering is broken. Since set-cookieΒ coming to the browser only includes a cookie for the SSR server, talking to the Appwrite server directly won't have a proper cookie - there is no auth cookie on the Appwrite hostname. To overcome this problem, we ensure the Appwrite hostname is a subdomain of the SSR hostname. For example, if our SSR server runs on, Appwrite needs a custom domain configured on With this setup, all requests to the Appwrite server will include auth cookies, and the user will be properly authorized. This is possible thanks to Appwrite prefixing the cookie domain with ., meaning all subdomains can also access the cookie.

🧰 Tech Stack

πŸ› οΈ Setup Server

  1. Setup Appwrite server
  2. Create project almostSsr

πŸ‘€ Setup Client

  1. Install libarries npm install
  2. Update AppwriteEndpoint in src/lib/AppwriteService.ts
  3. Start server npm run dev

πŸš€ Deployment

  1. Deploy the frontend on your production domain. For example,
  2. Add the frontend domain as a trusted platform in your Appwrite project.
  3. Add a custom domain to your Appwrite project, which is a subdomain of your frontend. For example,
  4. Update SsrHostname and AppwriteHostname in src/lib/AppwriteService.ts with proper domains.

🀝 Contributing

To contribute to frontend, make sure to use the Pink Design design system. Ensure both dark and light theme work properly, as well as responsivity on mobile, tablet and desktop.

When contributing with static files, ensure all images are in WEBP or SVG format.

πŸ–ΌοΈ Screenshots

πŸ€– Auto-generated documentation

Everything you need to build a Svelte project, powered by create-svelte.

Creating a project

If you're seeing this, you've probably already done this step. Congrats!

# create a new project in the current directory
npm create svelte@latest

# create a new project in my-app
npm create svelte@latest my-app


Once you've created a project and installed dependencies with npm install (or pnpm install or yarn), start a development server:

npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open


To create a production version of your app:

npm run build

You can preview the production build with npm run preview.

To deploy your app, you may need to install an adapter for your target environment.

Top categories

Loading Svelte Themes