README
8base react-native auth0 auth client
The 8base react-native auth0 auth client for the AuthProvider
.
ReactNativeAuth0AuthClient
Table of Contents
ReactNativeAuth0AuthClient
Create an instance of the react-native auth0 auth client.
Parameters
workspaceId
string Identifier of the 8base app workspace.domain
string Domain. See auth0 documentation.clientId
string Client id. See auth0 documentation.
Usage
...
import { AuthContext, AuthProvider, type AuthContextProps } from '@8base/auth';
import { ReactNativeAuth0AuthClient } form '@8base/react-native-auth0-auth-client';
const authClient = new ReactNativeAuth0AuthClient({
domain: 'domain',
clientId: 'client-id',
workspaceId: 'workspace-id',
});
...
const renderAuth = (auth) => {
const authorize = async () => {
const authData = await auth.authorize();
await auth.setAuthState({
token: authData.idToken,
email: authData.email,
});
};
const logout = async () => {
await auth.purgeAuthState();
};
if (auth.isAuthorized) {
return (
<View>
<Text>Hi ${auth.authState.email} !</Text>
<Button title='Logout' onPress={ logout } />
</View>
);
}
return (
<View>
<Button title='Authorize with auth0' onPress={ authorize } />
</View>
);
};
...
<AuthProvider authClient={ authClient }>
...
<AuthContext.Consumer>
{ renderAuth }
</AuthContext.Consumer>
...
</AuthProvider>