Closed matimusss closed 1 month ago
Example,
type DB = { todos: PostgresTable<{ id: number; done: boolean; task: Text }, 'id'>;};
const pgClient = new PostgrestClient
const jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoidG9kb191c2VyIn0.MbTpBHdNhsy0Cbi3rMhbzDai-0Y2bXVaHtD0g3VP-jk";
const headers = new Headers({
'Authorization': Bearer ${jwt}
});
const { rows2 } = await pgClient.post({ query: pgClient.query('todos'), data: { done: false, task:'todosfuncioan' }, headers: headers, });
There isn't any example showing how to handle JWT auth / headers, am I right? Shouldn't there be one, as postgREST typically uses this kind of auth?
Yes, you are right. I think that might be outside of the scope of this library, but I'm not sure about it. @kegjon do you have any opinions on this?
Thank you for the example. We identified 2 ways to provide JWT:
const pgClient = new PostgrestClient<DB>({ base: 'https://example.com' });
const res = await pgClient.get({
headers: new Headers({ Authorization: `Bearer ${jwtToken}` }),
query: pgClient.query("my-table"),
});
const axiosInstance = axios.create({ headers: { Authorization: `Bearer ${jwtToken}` } });
const pgClient = new PostgrestClient<DB>({
base: 'https://example.com',
axiosInstance,
});
...
const res = await pgClient.get({ query: pgClient.query("my-table") })
const res = await pgClient.post({ ... })
Hopefully it's obvious that you'll need to pass the header to every request for option 1., and just once for option 2. using Axios.
Closing since this is answered. We might decide to add an example in the future
There isn't any example showing how to handle JWT auth / headers, am I right?
Shouldn't there be one, as postgREST typically uses this kind of auth?
Greetings, thanks for your work!