Skip to content

Instantly share code, notes, and snippets.

@olsnacky
Last active December 31, 2020 23:40
Show Gist options
  • Save olsnacky/8f2bd20e916c01e1ec9575b42cf2f19f to your computer and use it in GitHub Desktop.
Save olsnacky/8f2bd20e916c01e1ec9575b42cf2f19f to your computer and use it in GitHub Desktop.
A TypeScript snippet for making external authenticated web API calls in Electron
import electron from 'electron';
function performExternalRequest() {
const cookieJar = electron.remote.session.defaultSession.cookies;
const cookie = {
url: 'https://youdomain.com',
name: 'your-cookie-name',
value: 'your-cookie-value'
};
cookieJar.set(cookie)
.then(() => {
fetch('https://your-api.domain/endpoint', {
credentials: 'include'
})
.then((response) => {
console.log(response);
})
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment