Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
nicolaslopezj committed Jan 12, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents fdebbcd + c2eb864 commit d7c2f0d
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
@@ -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)

0 comments on commit d7c2f0d

Please sign in to comment.