export const getJWT = async () => {
const jwt = await fetch(`https://cloud.appwrite.io/v1/account/jwt`, {
method: 'POST',
headers: {
Host: 'cloud.appwrite.io',
'Content-Type': 'application/json',
'X-Appwrite-Response-Format': '1.5.0',
'X-Appwrite-Project': projectId,
'X-Appwrite-Key': apiKey,
},
})
.then((response) => {
console.log(response)
return response.json();
})
.then((data) => {
console.log('jwt: ', data.jwt);
return data.jwt;
})
.catch((error) => {
console.error('Error:', error);
});
return jwt;
};
export const getAccount = async () => {
const jwt = await getJWT();
const response = await fetch(`${url}/account`, {
method: 'GET',
headers: {
Host: host,
'Content-Type': 'application/json',
'X-Appwrite-Response-Format': '1.5.0',
'X-Appwrite-Project': projectId,
'X-Appwrite-JWT': jwt,
},
})
.then((response) => {
return response.json();
})
.catch((error) => {
console.error('Error:', error);
});
return response;
};