Edits history of script submission #11126 for ' Identify an admin (intercom)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Intercom = {
    	apiVersion: string
    	token: string
    }
    /**
     * Identify an admin
     * 
    You can view the currently authorised admin along with the embedded app object (a "workspace" in legacy terminology).
    
    > 🚧 Single Sign On
    >
    > If you are building a custom "Log in with Intercom" flow for your site, and you call the `/me` endpoint to identify the logged-in user, you should not accept any sign-ins from users with unverified email addresses as it poses a potential impersonation security risk.
    
     */
    export async function main(auth: Intercom) {
    	const url = new URL(`https://api.intercom.io/me`)
    
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			'Intercom-Version': auth.apiVersion,
    			Authorization: 'Bearer ' + auth.token
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 536 days ago