//native
/**
* Generates an authentication token for the Terra mobile SDKs
* Creates a token to be used with initConnection() functions in the Terra mobile SDKs in order to create a user record for Apple Health or Samsung Health (or equivalent)
*/
export async function main(auth: RT.Terra) {
const url = new URL(`https://api.tryterra.co/v2/auth/generateAuthToken`)
const response = await fetch(url, {
method: 'POST',
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