33 lines
704 B
TypeScript
33 lines
704 B
TypeScript
import { adminCredentials } from '~/components/credentials';
|
|
import { getUrl } from './get-url';
|
|
import { headersWithAuth } from './headers-with-auth';
|
|
|
|
export const get = async (
|
|
id: string,
|
|
db = 'dyomedea_users',
|
|
credentials = adminCredentials()
|
|
) => {
|
|
if (!credentials) {
|
|
return null;
|
|
}
|
|
const { database } = credentials;
|
|
|
|
const headers = headersWithAuth(credentials);
|
|
if (!headers) {
|
|
return null;
|
|
}
|
|
|
|
// console.log({ caller: 'get', id, db, credentials, headers });
|
|
|
|
const response = await fetch(getUrl(id, db, credentials), {
|
|
method: 'GET',
|
|
mode: 'cors',
|
|
headers,
|
|
});
|
|
|
|
if (response.status >= 300) {
|
|
return null;
|
|
}
|
|
return await response.json();
|
|
};
|