Edits history of script submission #20931 for ' Generates an authentication token for the Terra mobile SDKs (terra)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //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