Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b63ec42
Step 1 Created with Base Layout
Mridul2820 Oct 2, 2023
054a236
Step 2: Create Next JS Project and Install dependencies
Mridul2820 Oct 2, 2023
9819f79
Step 3: Set up Appwrite
Mridul2820 Oct 2, 2023
8e52f0a
Step 4: Creating Signup, Login and Logout
Mridul2820 Oct 3, 2023
07c39d2
Step 5: Add database to store expenses
Mridul2820 Oct 3, 2023
5cb2ae8
Step 6: Create Expense List
Mridul2820 Oct 3, 2023
801d5cf
Step 7: Edit and Delete Expenses
Mridul2820 Oct 3, 2023
bb60439
Step 7: Add Pagination
Mridul2820 Oct 3, 2023
7e62867
Step 9: Test your project
Mridul2820 Oct 3, 2023
ebbed78
Changes to Doc
Mridul2820 Oct 3, 2023
117532a
Screenshots added
Mridul2820 Oct 3, 2023
5ec1974
Next JS to Next.js and Titles are now in sentence case
Mridul2820 Oct 3, 2023
976ae9e
Appwrite Screenshots in 1400x900 px
Mridul2820 Oct 3, 2023
bd8ab6b
Project Demo Change
Mridul2820 Oct 4, 2023
c96353b
Used pink.appwrite.io for Styles in Docs
Mridul2820 Oct 4, 2023
d2c834b
Added raw images after taking screenshots
Mridul2820 Oct 4, 2023
aa596c3
Screenshot Link Color Fix
Mridul2820 Oct 5, 2023
c33fec2
Added Updated Images
Mridul2820 Oct 7, 2023
d4a6ea2
Appwite Doc Links added
Mridul2820 Oct 7, 2023
d9b722e
Next.js App create steps added
Mridul2820 Oct 11, 2023
35a88be
Code Snippits update
Mridul2820 Oct 11, 2023
a3d39c5
Code Snippits Expended
Mridul2820 Oct 11, 2023
a3f39c4
App Image Change
Mridul2820 Oct 12, 2023
8b986d8
Convert to App Router
Mridul2820 Oct 12, 2023
64607d9
database ID and collection ID export
Mridul2820 Oct 12, 2023
5511863
Folder Path Updated for Files
Mridul2820 Oct 12, 2023
1e7f1c5
Step 1 Chnages Fixed
Mridul2820 Oct 13, 2023
df690a1
Step 3: env vars use to save the Appwrite Details
Mridul2820 Oct 13, 2023
7772797
Login and Signup Changes Done
Mridul2820 Oct 13, 2023
07329d0
Step 5 chnages Done
Mridul2820 Oct 13, 2023
05c0598
Chnages added as per Request
Mridul2820 Oct 13, 2023
03104ca
Chnages Updated
Mridul2820 Oct 14, 2023
acead7b
Code Nlock Imporoved
Mridul2820 Oct 14, 2023
bd24632
"use client"; in code snippits
Mridul2820 Oct 18, 2023
b4b6385
Pagination Chnages
Mridul2820 Oct 18, 2023
ab5653e
Decimal Increase
Mridul2820 Oct 25, 2023
e94b159
Signup and Login Code Merge
Mridul2820 Oct 26, 2023
273989b
Added comments to track the changes in list page after adding pagination
Mridul2820 Oct 26, 2023
3e0c43b
Specific Paths added
Mridul2820 Oct 26, 2023
4061003
Home Page file specify
Mridul2820 Oct 26, 2023
e537248
Added full code after some steps and file path comments in every code…
Mridul2820 Oct 27, 2023
887103d
Merge branch 'main' of https://github.com/Mridul2820/appwrite-website…
Mridul2820 Oct 27, 2023
105126f
Merge pull request #179 from Mridul2820/nextjs-tutorial
Oct 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/routes/docs/tutorials/nextjs/+layout.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script lang="ts">
import { globToTutorial } from '$lib/utils/tutorials.js';
import { setContext } from 'svelte';

export let data;
const tutorials = globToTutorial(data);
setContext('tutorials', tutorials);
</script>

<slot />
11 changes: 11 additions & 0 deletions src/routes/docs/tutorials/nextjs/+layout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { LayoutLoad } from './$types';

export const load: LayoutLoad = ({ url }) => {
const tutorials = import.meta.glob('./**/*.markdoc', {
eager: true
});
return {
tutorials,
pathname: url.pathname
};
};
6 changes: 6 additions & 0 deletions src/routes/docs/tutorials/nextjs/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { redirect } from '@sveltejs/kit';
import type { PageLoad } from './$types';

export const load: PageLoad = async () => {
throw redirect(303, '/docs/tutorials/nextjs/step-1');
};
28 changes: 28 additions & 0 deletions src/routes/docs/tutorials/nextjs/step-1/+page.markdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
layout: tutorial
title: Build an expense tracker with Next.js
description: Build a Next.js project using Appwrite.
step: 1
difficulty: beginner
readtime: 18
---

**Expense tracker** is a simple web application that allows you to track your expenses. It is built using [Next.js](https://nextjs.org/) [app router](https://nextjs.org/docs/app) and [Appwrite](https://appwrite.io/).

![Create project screen](/images/docs/tutorials/expense-tracker-app.png)

# Concepts {% #concepts %}
This tutorial will introduce the following concepts:

1. Introduction to Appwrite
2. Make first request
3. Implement authtentication
4. Intro to databases
5. Create, read, update and delete documents
5. Queries documents
6. Add pagination


# Prerequisites {% #prerequisites %}
1. Basic knowledge of JavaScript, [React](https://react.dev/learn) and [Next.js](https://nextjs.org/docs).
2. Have [Node.js](https://nodejs.org/en) and [NPM](https://www.npmjs.com/) installed on your computer
106 changes: 106 additions & 0 deletions src/routes/docs/tutorials/nextjs/step-2/+page.markdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
layout: tutorial
title: Create Next.js app
description: Create a Next.js project using Appwrite.
step: 2
---

# Create Next.js project {% #create-next-js-project %}

Create a new Next.js project using the `create-next-app` command.

```sh
npx create-next-app expense-tracker --eslint
cd expense-tracker
```

We are using the `--eslint` flags to add ESLint to our project.

What are the options you plan to take?

```sh
✔ Would you like to use TypeScript? … No / Yes : No
✔ Would you like to use Tailwind CSS? … No / Yes : No
✔ Would you like to use `src/` directory? … No / Yes : Yes
✔ Would you like to use App Router? (recommended) … No / Yes: Yes
✔ Would you like to customize the default import alias? … No / Yes : No

Creating a new Next.js app in expense-tracker.
```

You can also follow the responses from above. We will be using `app` directory for project. Also We are not using TypeScript and Tailwind CSS. So we can skip those options.

# Install dependencies {% #install-dependencies %}

Install the [JavaScript Appwrite SDK](https://appwrite.io/docs/sdks).

```sh
npm install appwrite
```

Install the [Appwrite CSS library](https://pink.appwrite.io/) and icons package. This will give us a nice looking UI for our app. We just have to use the classes provided by the CSS library.

```sh
npm install "@appwrite.io/pink" "@appwrite.io/pink-icons"
```

Import the CSS file and icons in the top of `app/layout.js` file.

```js
// /src/app/layout.js

import "@appwrite.io/pink";
import "@appwrite.io/pink-icons";
```

We are going to use a custom className `lite-bg` which we can define in the `globals.css` file.

```css
/* /src/app/globals.css */

.lite-bg {
background-color: hsl(var(--color-primary-100) / 0.2);
}
```

We will be using cookie to store the session token. So we need to install `next-cookie` package. We will also be using `react-hot-toast` to show toast messages.

```bash
npm install next-cookie react-hot-toast
```

We also have to add the `Toaster` component in the `app/layout.js` file. This component will render all toasts. The `layout.js` file will look like this.

```js
// /src/app/layout.js

import { Toaster } from "react-hot-toast";
import { Inter } from "next/font/google";

import "@appwrite.io/pink";
import "@appwrite.io/pink-icons";
import "./globals.css";

const inter = Inter({ subsets: ["latin"] });

export default function RootLayout({ children }) {
return (
<html lang="en">
<body className={inter.className}>
{children}
<Toaster position="bottom-right" />
</body>
</html>
);
}
```

# Start the development server {% #start-the-development-server %}

You can start the development server using the following command.

```sh
npm run dev
```

Open [http://localhost:3000](http://localhost:3000) in your browser to see the app.
73 changes: 73 additions & 0 deletions src/routes/docs/tutorials/nextjs/step-3/+page.markdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
layout: tutorial
title: Set up Appwrite
description: Learn how to set up Appwrite in your Next.js project
step: 3
---

# Create project {% #create-project %}

Head to the [Appwrite Console](https://cloud.appwrite.io/console). If this is your first time using Appwrite, create an account or log in to your existing account. Create a new project named `expanse-tracker`.

{% 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 %}

Then, under **Add a platform**, add a **Web app**. The **Hostname** should be localhost.

{% 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.

# Initialize Appwrite SDK {% #init-sdk %}

To use Appwrite in our Next.js app, we'll need to find our project ID. 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 %}

First create a file that will hold env variables. Create a new file `.env.local` in the root of your project. Replace `<YOUR_PROJECT_ID>` with your project ID

```js
// .env.local

NEXT_PUBLIC_APPWRITE_ENDPOINT = https://cloud.appwrite.io/v1
NEXT_PUBLIC_APPWRITE_PROJECT = <YOUR_PROJECT_ID>
```

Create a new file `src/config/appwrite.js` to hold our Appwrite related code.
Only one instance of the `Client()` class should be created per app.
Add the following code to it.

```js
// /src/config/appwrite.js

import { Client, Databases, Account } from "appwrite";

export const config = {
APPWRITE_ENDPOINT: process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT,
APPWRITE_PROJECT: process.env.NEXT_PUBLIC_APPWRITE_PROJECT,
};

const client = new Client();
client
.setEndpoint(config.APPWRITE_ENDPOINT)
.setProject(config.APPWRITE_PROJECT);

export const account = new Account(client);
export const database = new Databases(client);
```

Here we are using the Appwrite endpoints and project ID from the `.env.local` file to initialize the Appwrite SDK.
Loading