Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 334
Added next.js quick start guide#64
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
bfc65c23576cb2fada484e16f08ccc0247184e09e2be21ac8d04d16fFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -5,12 +5,150 @@ description: Learn how to use Appwrite to add authentication, user management, f | ||
| difficulty: beginner | ||
| readtime: 3 | ||
| --- | ||
| Learn to setup your first Next.js project powered by Appwrite. | ||
| {% section #step-1 step=1 title="Create project" %} | ||
| Head to the [Appwrite Console](https://cloud.appwrite.io/console). | ||
| Improve the docs, add this guide. | ||
| {% only_dark %} | ||
|  | ||
| {% /only_dark %} | ||
| {% only_light %} | ||
|  | ||
| {% /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. | ||
| Then, under **Add a platform**, add a **Web app**. The **Hostname** should be `localhost`. | ||
Meldiron marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| {% only_dark %} | ||
|  | ||
| {% /only_dark %} | ||
| {% only_light %} | ||
|  | ||
| {% /only_light %} | ||
| You can skip optional steps. | ||
| {% /section %} | ||
| {% section #step-2 step=2 title="Create Next.js project" %} | ||
| Create a Next.js project and create a **JavaScript** Next.js project. | ||
| ```sh | ||
| npx create-next-app@latest && cd my-app | ||
| ``` | ||
| {% /section %} | ||
| {% section #step-3 step=3 title="Install Appwrite SDK" %} | ||
| Install the JavaScript Appwrite SDK. | ||
| ```sh | ||
| npm install appwrite | ||
| ``` | ||
| {% /section %} | ||
| {% section #step-4 step=4 title="Define Appwrite service" %} | ||
| Find your project's ID in the **Settings** page. | ||
| {% only_dark %} | ||
|  | ||
| {% /only_dark %} | ||
| {% only_light %} | ||
|  | ||
| {% /only_light %} | ||
| Create a new file `app/appwrite.js` and add the following code to it, replace `<YOUR_PROJECT_ID>` with your project ID. | ||
| ```js | ||
| import { Client, Account } from 'appwrite'; | ||
| export const client = new Client(); | ||
| client | ||
| .setEndpoint('https://cloud.appwrite.io/v1') | ||
| .setProject('<YOUR_PROJECT_ID>'); // Replace with your project ID | ||
| export const account = new Account(client); | ||
| export { ID } from 'appwrite'; | ||
Meldiron marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ``` | ||
| {% /section %} | ||
| {% section #step-5 step=5 title="Create a login page" %} | ||
| Create or update `app/page.jsx` file and add the following code to it. | ||
| ```js | ||
| "use client"; | ||
| import { useState } from "react"; | ||
| import { account, ID } from "appwrite"; | ||
| const LoginPage = () => { | ||
| const [loggedInUser, setLoggedInUser] = useState(null); | ||
| const [email, setEmail] = useState(""); | ||
| const [password, setPassword] = useState(""); | ||
| const [name, setName] = useState(""); | ||
| const login = async (email, password) => { | ||
| const session = await account.createEmailSession(email, password); | ||
| setLoggedInUser(await account.get()); | ||
| }; | ||
| const register = async () => { | ||
| await account.create(ID.unique(), email, password, name); | ||
| login(email, password); | ||
| }; | ||
| const logout = async () => { | ||
| await account.deleteSession("current"); | ||
| setLoggedInUser(null); | ||
| }; | ||
| if (loggedInUser) { | ||
| return ( | ||
| <div> | ||
| <p>Logged in as {loggedInUser.name}</p> | ||
| <button type="button" onClick={logout}> | ||
| Logout | ||
| </button> | ||
| </div> | ||
| ); | ||
| } | ||
| return ( | ||
| <div> | ||
| <p>Not logged in</p> | ||
| <form> | ||
| <input | ||
| type="email" | ||
| placeholder="Email" | ||
Meldiron marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| value={email} | ||
| onChange={(e) => setEmail(e.target.value)} | ||
| /> | ||
| <input | ||
| type="password" | ||
| placeholder="Password" | ||
Meldiron marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| value={password} | ||
| onChange={(e) => setPassword(e.target.value)} | ||
| /> | ||
| <input | ||
| type="text" | ||
| placeholder="Name" | ||
Meldiron marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| value={name} | ||
| onChange={(e) => setName(e.target.value)} | ||
| /> | ||
| <button type="button" onClick={() => login(email, password)}> | ||
| Login | ||
| </button> | ||
| <button type="button" onClick={register}> | ||
vermakhushboo marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| Register | ||
| </button> | ||
| </form> | ||
| </div> | ||
| ); | ||
| }; | ||
| export default LoginPage; | ||
| ``` | ||
| {% /section %} | ||
| {% section #step-6 step=6 title="All set" %} | ||
vermakhushboo marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| Run your project with `npm run dev` and open [http://localhost:3000](http://localhost:3000) in your browser. | ||
| Don't forget to add some CSS to suit your style. | ||
| {% /section %} | ||
Uh oh!
There was an error while loading. Please reload this page.