docs: remove indents in code snippets, make separate section for configure permissions, and replace goTo with window.location.replace in code snippet

This commit is contained in:
choir27
2024-06-19 10:16:07 -04:00
parent bceac22cec
commit 2a0f4fc8d6
2 changed files with 21 additions and 5 deletions

View File

@@ -16,7 +16,6 @@ Create a new file `src/lib/context/user.jsx` and add the following code to it.
import { ID } from "appwrite";
import { createContext, useContext, useEffect, useState } from "react";
import { account } from "../appwrite";
import { goto } from "$app/navigation";
const UserContext = createContext();
@@ -30,7 +29,7 @@ export function UserProvider(props) {
async function login(email, password) {
const loggedIn = await account.createEmailPasswordSession(email, password);
setUser(loggedIn);
goTo("/");
window.location.replace("/"); // you can use different redirect method for your application
}
async function logout() {
@@ -82,7 +81,7 @@ function App() {
return (
<div>
<UserProvider>
<main>Home page</main>
<main>Home page</main>
</UserProvider>
</div>
);
@@ -106,7 +105,7 @@ function App() {
return (
<div>
<UserProvider>
<main>{isLoginPage ? <Login /> : <Home />}</main>
<main>{isLoginPage ? <Login /> : <Home />}</main>
</UserProvider>
</div>
);

View File

@@ -5,7 +5,7 @@ description: Add a database to your React application using Appwrite Web SDK.
step: 6
---
# Create collection {% #create-collection %}
In Appwrite, data is stored as a collection of documents. Create a collection in the [Appwrite Console](https://cloud.appwrite.io/) to store our ideas. To authorize users to view, create, and delete documents, set the collection's permissions for the user's needs.
In Appwrite, data is stored as a collection of documents. Create a collection in the [Appwrite Console](https://cloud.appwrite.io/) to store our ideas.
{% only_dark %}
![Create project screen](/images/docs/tutorials/dark/idea-tracker-collection.png)
@@ -14,6 +14,8 @@ In Appwrite, data is stored as a collection of documents. Create a collection in
![Create project screen](/images/docs/tutorials/idea-tracker-collection.png)
{% /only_light %}
## Attributes
Create a new collection with the following attributes:
| Field | Type | Required | Size |
|-------------|--------|----------|--------|
@@ -21,6 +23,21 @@ Create a new collection with the following attributes:
| title | String | Yes | 25 |
| description | String | No | 100 |
# Configure permissions {% #configure-permissions %}
{% only_dark %}
![Collection permissions screen](/images/docs/tutorials/dark/idea-tracker-permissions.png)
{% /only_dark %}
{% only_light %}
![Collection permissions screen](/images/docs/tutorials/idea-tracker-permissions.png)
{% /only_light %}
Navigate to the **Settings** tab of your collection, add the role **Any** and check the **Read** box.
Next, add a **Users** role and give them access to **Create** by checking those boxes.
These permissions apply to all documents in your new collection.
Finally, enable **Document security** to allow further permissions to be set at the document level.
Remember to click the **Update** button to apply your changes.
# Ideas context {% #ideas-context %}
Now that you have a collection to hold ideas, we can read and write to it from our app. Like we did with the user data, we will create a React context to hold our ideas.