Appwrite Loves Nuxt! Demo application with authorized server-side and client-side rendering.
Demo application with authorized server-side and client-side rendering.
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 cloud.appwrite.io
, and our app is on myapp.com
. SSR server on domain myapp.com
wonβt receive appwrite.io
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 myapp.com
, Appwrite needs a custom domain configured on appwrite.myapp.com
. 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.
almostSsr
npm install
AppwriteEndpoint
in nuxt.config.js
npm run dev
myapp.com
.appwrite.myapp.com
.SsrHostname
and AppwriteHostname
in nuxt.config.js
with proper domains.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.
Look at the Nuxt 3 documentation to learn more.
Make sure to install the dependencies:
# yarn
yarn install
# npm
npm install
# pnpm
pnpm install
Start the development server on http://localhost:3000
npm run dev
Build the application for production:
npm run build
Locally preview production build:
npm run preview
Check out the deployment documentation for more information.