0

Deauthenticates a user and deletes any cached data for them

by
Published Oct 17, 2025

Deletes all records of the user on Terra's end, revoking Terra's access to their data

Script terra Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
/**
3
 * Deauthenticates a user and deletes any cached data for them
4
 * Deletes all records of the user on Terra's end, revoking Terra's access to their data
5
 */
6
export async function main(auth: RT.Terra, user_id: string | undefined) {
7
	const url = new URL(`https://api.tryterra.co/v2/auth/deauthenticateUser`)
8
	for (const [k, v] of [['user_id', user_id]]) {
9
		if (v !== undefined && v !== '') {
10
			url.searchParams.append(k, v)
11
		}
12
	}
13
	const response = await fetch(url, {
14
		method: 'DELETE',
15
		headers: {
16
			'dev-id': auth.devId,
17
			'X-api-key': auth.apiKey
18
		},
19
		body: undefined
20
	})
21
	if (!response.ok) {
22
		const text = await response.text()
23
		throw new Error(`${response.status} ${text}`)
24
	}
25
	return await response.json()
26
}
27