Created
September 6, 2016 15:25
-
-
Save besingamkb/c1a4db3afd5a89847c6cfabd9fb8b520 to your computer and use it in GitHub Desktop.
authentication using apisauce for react-native
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
// a library to wrap and simplify api calls | |
import apisauce from 'apisauce' | |
import Reactotron from 'reactotron' // for IOS | |
const create = (baseURL = 'http://projectsnap.dev/api') => { | |
const api = apisauce.create({ | |
// base URL is read from the "constructor" | |
baseURL, | |
// here are some default headers | |
headers: { | |
'Cache-Control': 'no-cache' | |
}, | |
// 10 second timeout... | |
timeout: 10000 | |
}) | |
const login = (email, pword) => api.post('/authenticate', {email: email, password: pword}) | |
const apiMonitor = (response) => { | |
console.log("monitoring initiated") | |
console.log(JSON.stringify(response)) | |
} | |
api.addMonitor(apiMonitor) | |
return { | |
api, | |
login | |
} | |
} | |
// let's return back our create method as the default. | |
export default { | |
create | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment