Skip to content

Commit 31b130b

Browse files
committed
update read me
1 parent 28490c7 commit 31b130b

1 file changed

Lines changed: 32 additions & 42 deletions

File tree

README.md

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,46 @@
66
- Clean Code
77
- Test Code
88

9+
# React Native Auth0
910

10-
Basic use:
11+
A wrapper on auth0's react native library with common case features already implemented.
12+
13+
## Installation
14+
15+
1. Run on your terminal the following command:
16+
17+
```sh
18+
$ npm i @cobuildlab/react-native-auth0
19+
```
20+
## Usage
21+
22+
Create a new client instance using Auth0Native:
1123

1224
```tsx
13-
import React from 'react';
14-
import { View, Button, Text } from 'react-native';
15-
import { useAuth, AuthProviderConfig, AuthProvider } from '@cobuildlab/react-native-auth0';
16-
import { Credentials } from 'react-native-auth0';
17-
import AsyncStorage from '@react-native-async-storage/async-storage';
18-
19-
import { auth0 } from './src/shared/auth0/client';
20-
21-
const App: React.FC = () => {
22-
const { login, logout, isLoading, isAuthenticated } = useAuth();
23-
console.log('---- isAuthenticated --- ', isAuthenticated);
24-
console.log('---- isLoading --- ', isLoading);
25-
26-
return (
27-
<View>
28-
<Text>{isAuthenticated ? 'Im On' : 'Im Off'}</Text>
29-
<Button onPress={login} title="login" />
30-
<Button onPress={logout} title="logout" />
31-
</View>
32-
);
33-
};
34-
35-
const Conifg: AuthProviderConfig = {
36-
auth0,
37-
eichBaseToken: '8base-token',
38-
eichBaseAuthProfileId: 'my-profile-id',
39-
eichBaseEndpoint: '8base-environemnt-branch',
40-
removeCredentials: async () => {
41-
await AsyncStorage.removeItem('credentials_store');
42-
},
43-
saveCredentials: async (credentials) => {
25+
import { Auth0Native } from '@cobuildlab/react-native-auth0';
26+
27+
// AUTH0 options
28+
const AUTH0_OPTIONS = {
29+
clientId: AUTH_CLIENT_ID,
30+
domain: AUTH_CLIENT_DOMAIN,
31+
}
32+
33+
// You can handle the credentials obtained in auth0 and store them in the async store or another store of your choice
34+
const CREDENTIALS_HANDLER = {
35+
save: async (credentials): Promise<void> => {
4436
const value = JSON.stringify(credentials);
4537
await AsyncStorage.setItem('credentials_store', value);
4638
},
47-
getCredentials: async (): Promise<Credentials | null> => {
39+
get: async () => {
4840
const value = await AsyncStorage.getItem('credentials_store');
4941
return value != null ? JSON.parse(value) : null;
5042
},
51-
};
52-
53-
export const App = () => {
54-
return (
55-
<AuthProvider config={Conifg}>
56-
<App />
57-
</AuthProvider>
58-
);
59-
};
43+
clear: async () => {
44+
await AsyncStorage.removeItem('credentials_store');
45+
apolloClient.resetStore();
46+
},
47+
}
48+
49+
export const client = new Auth0Native(AUTH0_OPTIONS, CREDENTIALS_HANDLER);
6050
```
6151

0 commit comments

Comments
 (0)