Last active
December 31, 2020 23:40
-
-
Save olsnacky/8f2bd20e916c01e1ec9575b42cf2f19f to your computer and use it in GitHub Desktop.
A TypeScript snippet for making external authenticated web API calls in Electron
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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