Skip to content

Commit

Permalink
Merge pull request #30 from dbrrt/master
Browse files Browse the repository at this point in the history
React native README section added
  • Loading branch information
nicolaslopezj authored Jan 12, 2017
2 parents a4f0708 + faf2e33 commit c2eb864
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,53 @@ async function () {
```


### React-Native usage

```js

//First you'll need to import the Storage library that you'll use to store the user details (userId, tokens...),
// AsyncStorage is highly recommended.

import {
...
AsyncStorage
} from 'react-native';

import { loginWithPassword, userId, setTokenStore} from 'meteor-apollo-accounts'

// Then you'll have to define a TokenStore for your user data using setTokenStore (for instance when your component is mounted) :
setTokenStore({
set: async function ({userId, token, tokenExpires}) {
await AsyncStorage.setItem('Meteor.userId', userId)
await AsyncStorage.setItem('Meteor.loginToken', token)
// AsyncStorage doesn't support Date type so we'll store it as a String
await AsyncStorage.setItem('Meteor.loginTokenExpires', tokenExpires.toString())
},
get: async function () {
return {
userId: await AsyncStorage.getItem('Meteor.userId'),
token: await AsyncStorage.getItem('Meteor.loginToken'),
tokenExpires: await AsyncStorage.getItem('Meteor.loginTokenExpires')
}
}
})

// Finally, you'll be able to use asynchronously any method from the library :
async login (event) {
event.preventDefault();

try {
const id_ = await loginWithPassword({ "email", "password" }, this.client)
this.client.resetStore()
} catch (error) {

}
}

```



## Contributors

- [@nicolaslopezj](https://github.com/nicolaslopezj)
Expand Down

0 comments on commit c2eb864

Please sign in to comment.