Skip to content
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

docs: Remove setEndpoint #1223

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ Browsers have a default font size that users can change via the browser setting.
import { Client, Account } from "appwrite";

const client = new Client()
.setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
.setProject('5df5acd0d48c2') // Your project ID
.setProject('<PROJECT_ID>') // Your project ID

const account = new Account(client);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Meilisearch is a flexible and powerful user-focused search engine that can be ad
To use the function, you need the following set of keys:

- `APPWRITE_KEY` - API Key to talk to Appwrite backend APIs.To generate API Keys you can follow the documentation [here](https://appwrite.io/docs/getting-started-for-server#apiKey)
- `APPWRITE_ENDPOINT` - To get the Appwrite endpoint, you need to go to [Appwrite](https://cloud.appwrite.io/) and find it under “Settings”
- `APPWRITE_DATABASE_ID` - The ID of the Appwrite database that contains the collection to sync. You can find the documentation [here](https://appwrite.io/docs/databases).
- `APPWRITE_COLLECTION_ID` - The ID of the collection in the Appwrite database to sync.

Expand Down
2 changes: 0 additions & 2 deletions src/routes/blog/post/ai-crystal-ball/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ npm i appwrite openai
Lastly, we must create a `.env` file at the root of the directory and add the following:

```bash
PUBLIC_APPWRITE_ENDPOINT=
PUBLIC_APPWRITE_PROJECT_ID=
PUBLIC_APPWRITE_DATABASE_ID=
PUBLIC_APPWRITE_COLLECTION_ID_GITHUBDATA=
Expand All @@ -135,7 +134,6 @@ import { Client, Account, Databases } from 'appwrite';
import { env } from '$env/dynamic/public';

const client = new Client()
.setEndpoint(env.PUBLIC_APPWRITE_ENDPOINT)
.setProject(env.PUBLIC_APPWRITE_PROJECT_ID);

export const account = new Account(client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ import { Client, Account } from "appwrite";
const client = new Client();

client
.setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
.setProject('<PROJECT_ID>'); // Your project ID

const account = new Account(client);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ Here is what this would look like using Swift.
import Appwrite

let client = Client()
.setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
.setProject("5df5acd0d48c2") // Your project ID
.setKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key
.setProject("<PROJECT_ID>") // Your project ID
.setKey("<API_KEY>") // Your secret API key

let messaging = Messaging(client)

Expand All @@ -66,9 +65,8 @@ You can send SMS messages using a Server SDK. To send SMS messages immediately,
import Appwrite

let client = Client()
.setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
.setProject("5df5acd0d48c2") // Your project ID
.setKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key
.setProject("<PROJECT_ID>") // Your project ID
.setKey("<API_KEY>") // Your secret API key

let messaging = Messaging(client)

Expand Down Expand Up @@ -174,8 +172,7 @@ import { Client, Account } from "appwrite";
const client = new Client();

client
.setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
.setProject('<PROJECT_ID>'); // Your project ID

const account = new Account(client);

Expand Down Expand Up @@ -243,7 +240,6 @@ One of the most common examples of SDK Enums is OAuth providers. To log in with
import { Client, Account, OAuthProvider } from "appwrite";

const client = new Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>');

const account = new Account(client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ import { Appwrite, Databases, Query } from "appwrite";

const client = new Appwrite();
client
.setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
.setProject('articles-demo'); // Your project ID
const databases = new Databases(client);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ import { Client, Account, ID } from 'react-native-appwrite';
const client = new Client();

client
.setEndpoint('http://cloud.appwrite.io/v1') // Your Appwrite Endpoint
.setProject('455x34dfkj') // Your project ID
.setProject('455x34dfkj') // Your project ID
.setPlatform('com.example.myappwriteapp'); // Your application ID or bundle ID

const account = new Account(client);
Expand Down
7 changes: 2 additions & 5 deletions src/routes/blog/post/building-init-giveaway-app/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ We then entered the application directory, installed the Appwrite Web SDK and Pi

```js
// ./src/lib/constants.js

export const APPWRITE_ENDPOINT = 'https://cloud.appwrite.io/v1';

export const APPWRITE_PROJECT = '<PROJECT_ID>';

export const DATABASE_NAME = '<DATABASE_ID>';
Expand All @@ -104,11 +101,11 @@ After the constants were added, we could now set up the Appwrite SDK.
// ./src/lib/appwrite.js

import { Account, Client, Databases } from 'appwrite';
import { APPWRITE_ENDPOINT, APPWRITE_PROJECT } from './constants';
import { APPWRITE_PROJECT } from './constants';

export const client = new Client();

client.setEndpoint(APPWRITE_ENDPOINT).setProject(APPWRITE_PROJECT);
client.setProject(APPWRITE_PROJECT);

export const account = new Account(client);

Expand Down
2 changes: 0 additions & 2 deletions src/routes/blog/post/csr-vs-ssr-with-nextjs/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ The admin client must be set with an API key that has the necessary scopes in or

```jsx
const adminClient = new Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>')
.setKey('<API_KEY>')
```
Expand Down Expand Up @@ -90,7 +89,6 @@ The session client accepts the generated session secret and sets it using the `c

```jsx
const sessionClient = new Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>')
```

Expand Down
4 changes: 1 addition & 3 deletions src/routes/blog/post/email-otp-auth-sveltekit/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ npm i
Also, create a file `.env` in the root directory and add your Appwrite API endpoint and project ID.

```
PUBLIC_APPWRITE_ENDPOINT=
PUBLIC_APPWRITE_PROJECT_ID=
```

Expand All @@ -111,11 +110,10 @@ npm i appwrite
As soon as that’s done, we can start preparing our application logic. For that, visit the `src/lib` directory and create a file `appwrite.js`. Add the following code to the same.

```js
import { PUBLIC_APPWRITE_ENDPOINT, PUBLIC_APPWRITE_PROJECT_ID } from "$env/static/public";
import { PUBLIC_APPWRITE_PROJECT_ID } from "$env/static/public";
import { Client, Account } from "appwrite";

const client = new Client()
.setEndpoint(PUBLIC_APPWRITE_ENDPOINT)
.setProject(PUBLIC_APPWRITE_PROJECT_ID);

export const account = new Account(client);
Expand Down
1 change: 0 additions & 1 deletion src/routes/blog/post/enhancing-type-safety/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ With the latest release of Appwrite, we have taken steps to improve type safety
import { Client, Account, OAuthProvider } from "appwrite";

const client = new Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>');

const account = new Account(client);
Expand Down
1 change: 0 additions & 1 deletion src/routes/blog/post/enums-api-design/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ With the latest release of Appwrite, we have taken steps to improve type safety
import { Client, Account, OAuthProvider } from "appwrite";

const client = new Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>');

const account = new Account(client);
Expand Down
1 change: 0 additions & 1 deletion src/routes/blog/post/image-classification/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ def main(context):

client = (
Client()
.set_endpoint("https://cloud.appwrite.io/v1")
.set_project(os.environ["APPWRITE_FUNCTION_PROJECT_ID"])
.set_key(os.environ["APPWRITE_API_KEY"])
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ First, we initialize the login process by sending an email with the magic URL. I
import { Client, Account, ID } from "appwrite";

const client = new Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>');

const account = new Account(client);
Expand Down Expand Up @@ -103,7 +102,6 @@ First, we initialize the login process by sending an email. If the email has nev
import { Client, Account, ID } from "appwrite";

const client = new Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>');

const account = new Account(client);
Expand Down Expand Up @@ -138,7 +136,6 @@ First, we initialize the login process by sending an SMS. If the phone number ha
import 'package:appwrite/appwrite.dart';

final client = Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>');

final account = Account(client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ npm i
Next, we shall create a `.env` file at the root of the directory and add the following:

```bash
PUBLIC_APPWRITE_ENDPOINT=
PUBLIC_APPWRITE_PROJECT_ID=
APPWRITE_API_KEY=
```
Expand All @@ -81,15 +80,13 @@ We will then develop our API route `/auth` by creating a file `./src/routes/auth

```js
import { Client, Users, ID, Query } from 'node-appwrite';
import { PUBLIC_APPWRITE_ENDPOINT, PUBLIC_APPWRITE_PROJECT_ID } from '$env/static/public'; // Gets the public environment variables shared with the client
import { PUBLIC_APPWRITE_PROJECT_ID } from '$env/static/public'; // Gets the public environment variables shared with the client
import { env } from '$env/dynamic/private'; // Gets the private server-only environment variable

const endpoint = PUBLIC_APPWRITE_ENDPOINT;
const projectId = PUBLIC_APPWRITE_PROJECT_ID;
const apiKey = env.APPWRITE_API_KEY;

const client = new Client()
.setEndpoint(endpoint)
.setProject(projectId)
.setKey(apiKey);

Expand Down Expand Up @@ -176,13 +173,11 @@ npm i appwrite

```js
import { Client, Account } from 'appwrite';
import { PUBLIC_APPWRITE_ENDPOINT, PUBLIC_APPWRITE_PROJECT_ID } from '$env/static/public';
import { PUBLIC_APPWRITE_PROJECT_ID } from '$env/static/public';

const endpoint = PUBLIC_APPWRITE_ENDPOINT;
const projectId = PUBLIC_APPWRITE_PROJECT_ID;

const client = new Client()
.setEndpoint(endpoint) // Your API Endpoint
.setProject(projectId); // Your project ID;

export const account = new Account(client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,14 @@ let client;
export default async ({ req, res, log, error }) => {
// Connect to database
if(!client) {
const { PGHOST, PGDATABASE, PGUSER, PGPASSWORD, ENDPOINT_ID } = process.env;
const { PGHOST, PGDATABASE, PGUSER, PGPASSWORD } = process.env;
client = postgres({
host: PGHOST,
database: PGDATABASE,
username: PGUSER,
password: PGPASSWORD,
port: 5432,
ssl: 'require',
connection: {
options: `project=${ENDPOINT_ID}`,
},
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ import { Client, Account, ID } from 'react-native-appwrite';
const client = new Client();

client
.setEndpoint('http://cloud.appwrite.io/v1') // Your Appwrite Endpoint
.setProject('455x34dfkj') // Your project ID
.setProject('455x34dfkj') // Your project ID
.setPlatform('com.example.myappwriteapp'); // Your application ID or bundle ID

const account = new Account(client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Bringing along benefits such as massively reducing friction when using routes th
import { Client, Account, OAuthProvider } from "appwrite";

const client = new Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>');

const account = new Account(client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ The admin client will need to be initialized with an API key in order to bypass
import { Client } from "node-appwrite"

const adminClient = new Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('<YOUR_PROJECT_ID>')
.setKey('<YOUR_API_KEY>')
.setProject('<PROJECT_ID>')
.setKey('<API_KEY>')
```

### Session Client
Expand All @@ -86,8 +85,7 @@ A session client will allow us to make requests as an authenticated end-user wit

```jsx
const sessionClient = new Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('<YOUR_PROJECT_ID>')
.setProject('<PROJECT_ID>')

const session = req.cookies.session

Expand Down Expand Up @@ -117,7 +115,6 @@ import { parseCookie } from "next/dist/compiled/@edge-runtime/cookies";

export function createAdminClient() => {
const client = new Client()
.setEndpoint(process.env.PUBLIC_APPWRITE_ENDPOINT)
.setProject(process.env.PUBLIC_APPWRITE_PROJECT)
.setKey(process.env.APPWRITE_API_KEY)

Expand All @@ -130,7 +127,6 @@ export function createAdminClient() => {

export function createSessionClient(headers) {
const client = new Client()
.setEndpoint(process.env.PUBLIC_APPWRITE_ENDPOINT)
.setProject(process.env.PUBLIC_APPWRITE_PROJECT)

const cookies = parseCookie(headers.get('cookie') ?? '')
Expand Down
5 changes: 2 additions & 3 deletions src/routes/blog/post/messaging-explained/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ Here’s an example of how you would programmatically send an SMS to a topic usi
const sdk = require('node-appwrite');

const client = new sdk.Client()
.setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
.setProject('5df5acd0d48c2') // Your project ID
.setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key
.setProject('<PROJECT_ID>') // Your project ID
.setKey('<API_KEY>'); // Your secret API key

const messaging = new sdk.Messaging(client);
.
Expand Down
1 change: 0 additions & 1 deletion src/routes/blog/post/oauth-openid/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ Once that is done, you can use any of the Appwrite client SDKs to implement OAut
import { Client, Account, OAuthProvider } from "appwrite";

const client = new Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>');

const account = new Account(client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ Appwrite Authentication also leverages password hashing algorithms to allow deve
import { Client, Account, ID } from "appwrite";

const client = new Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>');

const account = new Account(client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ const client = new sdk.Client();
const messaging = new sdk.Messaging(client);

client
.setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
.setProject('5df5acd0d48c2') // Your project ID
.setKey('919c2d18fb5d4...a2ae413da83346ad2'); // Your secret API key
.setProject('<PROJECT_ID>') // Your project ID
.setKey('<API_KEY>'); // Your secret API key

const message = await messaging.createPush(
sdk.ID.unique(), // messageId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ All of the Appwrite client SDKs for Web, Flutter, iOS, or Android come with buil
import { Client } from "appwrite";

const client = new Client()
.setEndpoint('<https://cloud.appwrite.io/v1>')
.setProject('<PROJECT_ID>');

client.subscribe('account', response => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,12 @@ import { Client, Account, OAuthProvider } from 'appwrite'

const client = new Client()
client
.setEndpoint('https://cloud.appwrite.io/v1')// The Appwrite API endpoint
.setProject('project-id')// Your Appwrite project IDexport const account = new Account(client)
.setProject('project-id') // Your Appwrite project IDexport const account = new Account(client)
export { OAuthProvider }

```

In the `appwrite.js` file, the `Client` object, used to interact with Appwrite services, is initialized with the Appwrite API endpoint and your project ID. The `account` object is created using the client to interact with the Appwrite account service, while the `OAuthProvider` is an enum that contains the OAuth2 providers supported by Appwrite. We are exporting it from this file so you don't have to import both from `appwrite` and `appwrite.js` when you need to use both account and OAuthProvider in a component.
In the `appwrite.js` file, the `Client` object, used to interact with Appwrite services, is initialized with your project ID. The `account` object is created using the client to interact with the Appwrite account service, while the `OAuthProvider` is an enum that contains the OAuth2 providers supported by Appwrite. We are exporting it from this file so you don't have to import both from `appwrite` and `appwrite.js` when you need to use both account and OAuthProvider in a component.

# Create authentication functions

Expand Down
Loading
Loading