Get Viewer Display Name using Extension Frontend Helix Token

Updated code - Using most recent Helix Token –

const getTwitchUserName = (userid) => {


    window.Twitch.ext.onAuthorized(function (auth) {

        const defaultOptions = {
            headers: {
                'Authorization': auth.helixToken ? `Extension ${auth.helixToken}` : '',
                'client-id': clientID ? `${clientID}` : '',
            }
        }

        api.getTwitchUserName(userid, defaultOptions).then(response => {

            if (response != false) {
                return response.data.data[0]["login"] + " (" + response.data.data[0]["display_name"] + ")"
            }
            else {
                return null
            }
        }).catch(error => {
            return null
        })
    })
}

Also its a good idea to check that the user granted permissions first :

        let viewer_id = authentication.getUserId() 

       if(viewer_id != null) {

        // Note this runs an api call so the viewerName won't be populated until the 
         api call has a response, so adjust code accordingly
        let viewerName = getTwitchUserName(viewer_id)

       }