Skip to content

Instantly share code, notes, and snippets.

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
// do login logic here
// All the requests will happen now that the user is authenticated again
setTimeout(login, 60 * 5 * 1000 /* re-login every five minutes */)
export default {
fetchData: funnel.wrap(fetchData),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment