Last active
April 11, 2017 06:37
-
-
Save ekryski/6c4d2b511ce4eea847dc to your computer and use it in GitHub Desktop.
Feathers React Native Configuration
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 { AsyncStorage } from 'react-native'; | |
import feathers from 'feathers/client' | |
import hooks from 'feathers-hooks'; | |
import socketio from 'feathers-socketio/client' | |
import authentication from 'feathers-authentication-client'; | |
if(!global._babelPolyfill) { require('babel-polyfill'); } | |
// Need to require instead of import so we can set the user agent first | |
const io = require('socket.io-client/socket.io'); | |
const host = 'http://localhost:3030'; | |
let socket = io(host, { transports: ['websocket'] }); | |
// Set up Feathers client side | |
let app = feathers(); | |
// Register hooks module | |
app.configure(hooks()); | |
// Register socket.io | |
app.configure(socketio(socket)); | |
// Set up authentication with a store to cache your access token | |
app.configure(authentication({ storage: AsyncStorage })); | |
// Authenticating using a email and password | |
app.authenticate({ | |
strategy: 'local', | |
email: '[email protected]', | |
password: 'admin' | |
}).then(function(result){ | |
console.log('Authenticated!', result); | |
// Find our users on the server via sockets | |
app.service('users').find({}).then(function(users){ | |
console.log('Users!', users); | |
}); | |
}).catch(function(error){ | |
console.error('Error authenticating!', error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment