Back

How to add API Keys when initialize Appwrite client

  • 0
  • Web
  • Databases
  • Auth
  • Self Hosted
  • Functions
Stefan
1 May, 2024, 01:33
TypeScript
import { Account, Client, Databases } from "appwrite";

const APPWRITE_ENDPOINT = import.meta.env.VITE_APPWRITE_ENDPOINT;
const APPWRITE_PROJECT_ID = import.meta.env.VITE_APPWRITE_PROJECT_ID;
const APPWRITE_API_ID = import.meta.env.VITE_APPWRITE_API_KEY;

const client = new Client()
  .setEndpoint(APPWRITE_ENDPOINT)
  .setProject(APPWRITE_PROJECT_ID)
  .setKey(APPWRITE_API_KEY); // This code doesn't work

export const account = new Account(client);
export const databases = new Databases(client);

Would like to get supported

TL;DR
Developers are inquiring about adding API keys when initializing the Appwrite client. They express concerns about limitations in the client-side Appwrite, inquire about the benefits of `node-appwrite` vs. `appwrite`, and question transitioning from client-side to server-side. The issue with the `setKey` method not working in the provided code snippet is due to a casing error (should be `setKey` not `setkey`). It is clarified that API keys should not be used client-side. The correct implementation should be corrected as follows: ```js import { Account, Client, Databases } from "appwrite"; const
Guille
1 May, 2024, 01:37

It should be setKey and not setkey

Stefan
1 May, 2024, 01:38

Sorry, just spell mistake. However, doesn't work

Steven
1 May, 2024, 01:38

You cannot/should not use API keys client side. That's why the method doesn't exist

Stefan
1 May, 2024, 01:39

I'm getting that setKey does not exist on Client class

Guille
1 May, 2024, 01:39

Oh yes as @Steven say, setKey is for server SDK

Stefan
1 May, 2024, 01:40

Then should I transfer from client-side to server-side?

Stefan
1 May, 2024, 01:45

Which one is better? node-appwrite or appwrite?

Guille
1 May, 2024, 01:46

It just depends on what you want to do

Stefan
1 May, 2024, 01:48

Why is there a lot of limitations in client side Appwrite?

Steven
1 May, 2024, 01:55

Are you allowed to go to GitHub and fetch all users with their hashed passwords and emails?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more