diff --git a/src/routes/docs/quick-starts/astro/+page.markdoc b/src/routes/docs/quick-starts/astro/+page.markdoc index e088f6178d..0d10480fac 100644 --- a/src/routes/docs/quick-starts/astro/+page.markdoc +++ b/src/routes/docs/quick-starts/astro/+page.markdoc @@ -3,14 +3,282 @@ layout: article title: Start with Astro description: Learn how to use Appwrite to add authentication, user management, file storage, and more to your Astro apps. difficulty: beginner -readtime: 3 +readtime: 4 --- +Learn how to setup your first Astro project powered by Appwrite. +{% section #step-1 step=1 title="Create Appwrite project" %} +Head to the [Appwrite Console](https://cloud.appwrite.io/console). -Improve the docs, add this guide. +{% only_dark %} +![Create project screen](/images/docs/quick-starts/dark/create-project.png) +{% /only_dark %} +{% only_light %} +![Create project screen](/images/docs/quick-starts/create-project.png) +{% /only_light %} -We still don't have this guide in place, but we do have some great news. -The Appwrite docs, just like Appwrite, is completely open sourced. -This means, anyone can help improve them and add new guides and tutorials. +If this is your first time using Appwrite, create an account and create your first project. -If you see this page, **we're actively looking for contributions to this page**. -Follow our contribution guidelines, open a PR to [our Website repo](https://github.com/appwrite/website), and collaborate with our core team to improve this page. \ No newline at end of file +Then, under **Add a platform**, add a **Web app**. The **Hostname** should be `localhost`. + +{% partial file="note-on-cors.md" /%} + +{% only_dark %} +![Add a platform](/images/docs/quick-starts/dark/add-platform.png) +{% /only_dark %} +{% only_light %} +![Add a platform](/images/docs/quick-starts/add-platform.png) +{% /only_light %} + +You can skip optional steps. + +{% /section %} +{% section #step-2 step=2 title="Create Astro project" %} +Create Astro project by running the following command: + +```sh +npm create astro@latest appwrite-astro +``` + +When prompted, configure your project with these recommended settings: +- **How would you like to start your new project?** → basic +- **Install dependencies?** → Yes +- **Initialize a new git repository?** → Yes + +These settings will create a basic Astro project in `./appwrite-astro` directory ready to get started with Appwrite. + +{% /section %} + +{% section #step-3 step=3 title="Setup Appwrite" %} +Find your project's ID in the **Settings** page. + +{% only_dark %} +![Project settings screen](/images/docs/quick-starts/dark/project-id.png) +{% /only_dark %} +{% only_light %} +![Project settings screen](/images/docs/quick-starts/project-id.png) +{% /only_light %} + +Add environment variables schema to your projects `astro.config.mjs` file. + +```js +import { defineConfig, envField } from "astro/config"; + +// https://astro.build/config +export default defineConfig({ + env: { + validateSecrets: true, + schema: { + APPWRITE_ENDPOINT: envField.string({ + access: "public", + context: "client", + url: true, + min: 1, + }), + APPWRITE_PROJECT_ID: envField.string({ + access: "public", + context: "client", + min: 1, + }) + } + } +}); +``` + +Declare the variables in your `.env` file. + +```env +APPWRITE_ENDPOINT=# https://.cloud.appwrite.io/v1 +APPWRITE_PROJECT_ID=# Find your project's ID in the Settings page +``` + +Install the Appwrite JavaScript SDK. + +```sh +npm install appwrite +``` + +Create a new file `src/lib/appwrite.ts` with the following code. + +```ts +import { Client, Account } from "appwrite"; +import { APPWRITE_ENDPOINT, APPWRITE_PROJECT_ID } from "astro:env/client"; + +export { type Models, ID } from "appwrite"; + +export const client = new Client() + .setEndpoint(APPWRITE_ENDPOINT) + .setProject(APPWRITE_PROJECT_ID); + +export const account = new Account(client); + +``` +{% /section %} +{% section #step-4 step=4 title="Create a login page" %} +Create or update `src/pages/index.astro` with the following code. + +{% info title="" %} +This is similar to vanilla js considering Astro is not a frontend framework +{% /info %} + + ```ts + --- +import Layout from "../layouts/Layout.astro"; +--- + +

Welcome to Appwrite with Astro!

+ +
+

Welcome

+ +
+ +
+

Login / Register

+ + +
+ + +
+ + +
+
+ + + + + ``` +{% /section %} + +{% section #step-5 step=5 title="All set" %} +Run your project with `npm run dev` and open [localhost on port 4321](http://localhost:4321) in your browser. +{% /section %}