INNER CODE UNIT · JavaScript
login
aelassas/wexflow · samples/clients/client/node/index.js:6
async function login(user, pass, stayConnected = false) {
const res = await fetch(`${baseUrl}/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username: user, password: pass, stayConnected })
})
if (!res.ok) {
throw new Error(`HTTP ${res.status} - ${res.statusText}`)
}
const data = await res.json()
return data.access_token
}
try {
const token = await login(username, password)
const res = await fetch(`${baseUrl}/start?w=${workflowId}`, {
method: 'POST',
headers: { 'Authorization': `Bearer ${token}` }