Back

[SOLVED] where do i get my secret api key? (beginner)

  • 0
  • Web
bonndubz
19 Nov, 2023, 18:53

talking about this example right here:

TypeScript
const sdk = require('node-appwrite'); // also is this possible to turn into an import module?

const client = new sdk.Client();

const databases = new sdk.Databases(client);

client
    .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('xxx') // Your project ID
    .setKey('???') // Your secret API key
;

i also have Client.js and i wanna know if this code above is gonna mess with this:

TypeScript
import { Client, Account } from 'appwrite';

export const client = new Client();

client
    .setEndpoint(import.meta.env.VITE_REACT_ENDPOINT)
    .setProject(import.meta.env.VITE_REACT_PROJ); // Replace with your project ID

export const account = new Account(client);
export { ID } from 'appwrite'; 

i was thinking of doing something like

TypeScript
import { Client, Account, Databases } from 'appwrite';

export const client = new Client();

client
    .setEndpoint(import.meta.env.VITE_REACT_ENDPOINT)
    .setProject(import.meta.env.VITE_REACT_PROJ); // Replace with your project ID

export const account = new Account(client);
export const databases = new Databases(client); 
export { ID } from 'appwrite'; 

but i dont really know if thats going to work, anyone could help me?

TL;DR
Title: How to get a secret API key and use it in a React web app The code you provided can be modified to work with the Appwrite SDK in a React web app. However, it's not necessary to include the secret API key on the client side. Instead, use the web SDK and set permissions for the desired database (e.g., "posts"). Here's a simplified version of the code: ```js import { Client, Account, Databases } from 'appwrite'; // Create a client instance export const client = new Client(); client.setEndpoint(import.meta.env.VITE_REACT_ENDPOINT); client.set
bonndubz
19 Nov, 2023, 18:54

where do i get my secret api key? (beginner)

D5
19 Nov, 2023, 19:07

In client side you should not set API key

D5
19 Nov, 2023, 19:33

Or this is server side?

bonndubz
19 Nov, 2023, 19:52

idk its in my project

bonndubz
19 Nov, 2023, 19:52

its kinda both things at the same time

bonndubz
19 Nov, 2023, 19:52

but im using an ENV file

D5
19 Nov, 2023, 19:53

This is a react web app?

bonndubz
19 Nov, 2023, 19:53

yessir

D5
19 Nov, 2023, 19:53

Then that's client side

bonndubz
19 Nov, 2023, 19:53

yeah

bonndubz
19 Nov, 2023, 19:53

idk where to actually put stuff

D5
19 Nov, 2023, 19:54

Not needed using server side SDK, use web SDK and don't use any API key

D5
19 Nov, 2023, 19:54

What code?

bonndubz
19 Nov, 2023, 19:54

no api key?

D5
19 Nov, 2023, 19:54

Nope, don't use it

bonndubz
19 Nov, 2023, 19:54

wait then how do i access my database?

D5
19 Nov, 2023, 19:54

Set permissions for such user

D5
19 Nov, 2023, 19:54

Or users

bonndubz
19 Nov, 2023, 19:55

the thing is

bonndubz
19 Nov, 2023, 19:55

the database is a collection of posts

bonndubz
19 Nov, 2023, 19:55

like its not just users

D5
19 Nov, 2023, 19:55

Yes

bonndubz
19 Nov, 2023, 19:55

i wanna access the "posts" database rn

D5
19 Nov, 2023, 19:55

You should set permissions for it

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