diff --git a/README.md b/README.md index 47e263f..d46321a 100644 --- a/README.md +++ b/README.md @@ -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)