-
Notifications
You must be signed in to change notification settings - Fork 297
📚 Documentation: Tutorial for Next JS #179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gewenyu99
merged 42 commits into
appwrite:feat-next-js-tutorial
from
Mridul2820:nextjs-tutorial
Oct 30, 2023
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
b63ec42
Step 1 Created with Base Layout
Mridul2820 054a236
Step 2: Create Next JS Project and Install dependencies
Mridul2820 9819f79
Step 3: Set up Appwrite
Mridul2820 8e52f0a
Step 4: Creating Signup, Login and Logout
Mridul2820 07c39d2
Step 5: Add database to store expenses
Mridul2820 5cb2ae8
Step 6: Create Expense List
Mridul2820 801d5cf
Step 7: Edit and Delete Expenses
Mridul2820 bb60439
Step 7: Add Pagination
Mridul2820 7e62867
Step 9: Test your project
Mridul2820 ebbed78
Changes to Doc
Mridul2820 117532a
Screenshots added
Mridul2820 5ec1974
Next JS to Next.js and Titles are now in sentence case
Mridul2820 976ae9e
Appwrite Screenshots in 1400x900 px
Mridul2820 bd8ab6b
Project Demo Change
Mridul2820 c96353b
Used pink.appwrite.io for Styles in Docs
Mridul2820 d2c834b
Added raw images after taking screenshots
Mridul2820 aa596c3
Screenshot Link Color Fix
Mridul2820 c33fec2
Added Updated Images
Mridul2820 d4a6ea2
Appwite Doc Links added
Mridul2820 d9b722e
Next.js App create steps added
Mridul2820 35a88be
Code Snippits update
Mridul2820 a3d39c5
Code Snippits Expended
Mridul2820 a3f39c4
App Image Change
Mridul2820 8b986d8
Convert to App Router
Mridul2820 64607d9
database ID and collection ID export
Mridul2820 5511863
Folder Path Updated for Files
Mridul2820 1e7f1c5
Step 1 Chnages Fixed
Mridul2820 df690a1
Step 3: env vars use to save the Appwrite Details
Mridul2820 7772797
Login and Signup Changes Done
Mridul2820 07329d0
Step 5 chnages Done
Mridul2820 05c0598
Chnages added as per Request
Mridul2820 03104ca
Chnages Updated
Mridul2820 acead7b
Code Nlock Imporoved
Mridul2820 bd24632
"use client"; in code snippits
Mridul2820 b4b6385
Pagination Chnages
Mridul2820 ab5653e
Decimal Increase
Mridul2820 e94b159
Signup and Login Code Merge
Mridul2820 273989b
Added comments to track the changes in list page after adding pagination
Mridul2820 3e0c43b
Specific Paths added
Mridul2820 4061003
Home Page file specify
Mridul2820 e537248
Added full code after some steps and file path comments in every code…
Mridul2820 887103d
Merge branch 'main' of https://github.com/Mridul2820/appwrite-website…
Mridul2820 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/). | ||
|
|
||
|  | ||
|
|
||
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
Mridul2820 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 | ||
Mridul2820 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| 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. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 %} | ||
|  | ||
| {% /only_dark %} | ||
| {% only_light %} | ||
|  | ||
| {% /only_light %} | ||
|
|
||
| Then, under **Add a platform**, add a **Web app**. The **Hostname** should be localhost. | ||
|
|
||
| {% only_dark %} | ||
|  | ||
| {% /only_dark %} | ||
| {% only_light %} | ||
|  | ||
| {% /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 %} | ||
|  | ||
| {% /only_dark %} | ||
| {% only_light %} | ||
|  | ||
| {% /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. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.