//native
/**
* Deauthenticates a user and deletes any cached data for them
* Deletes all records of the user on Terra's end, revoking Terra's access to their data
*/
export async function main(auth: RT.Terra, user_id: string | undefined) {
const url = new URL(`https://api.tryterra.co/v2/auth/deauthenticateUser`)
for (const [k, v] of [['user_id', user_id]]) {
if (v !== undefined && v !== '') {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'DELETE',
headers: {
'dev-id': auth.devId,
'X-api-key': auth.apiKey
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 235 days ago