Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using promise-funnel for authentication
import createFunnel from 'promise-funnel'
const funnel = createFunnel()
function fetchData(...options) {
// This will fail if the user is unauthenticated
return fetch(...options)
}
function login() {
// all requests will be stopped while authentication is happening
funnel.cork()
// do login logic here
// All the requests will happen now that the user is authenticated again
funnel.uncork()
}
setTimeout(login, 60 * 5 * 1000 /* re-login every five minutes */)
export default {
fetchData: funnel.wrap(fetchData),
login,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment