8base web auth0 auth client
The 8base auth0 auth client for the AuthProvider
.
WebAuth0AuthClient
Table of Contents
WebAuth0AuthClient
Create instacne of the web 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.redirectUri
string Redurect uri. See auth0 documentation.
Usage
import { AuthContext, AuthProvider, type AuthContextProps } from '@8base/auth';
import { WebAuth0AuthClient } from '@8base/web-auth0-auth-client';
const authClient = new WebAuth0AuthClient({
domain: 'domain',
clientId: 'client-id',
redirectUri: `${window.location.origin}/auth/callback`,
logoutRedirectUri: `${window.location.origin}/auth`,
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();
await auth.logout();
};
if (auth.isAuthorized) {
return (
<div>
<p>Hi ${auth.authState.email} !</p>
<button type='button' onClick={ logout }>Logout</button>
</div>
);
}
return (
<div>
<button type='button' onClick={ authorize }>Authorize with auth0<button/>
</div>
);
};
...
<AuthProvider authClient={ authClient }>
...
<AuthContext.Consumer>
{ renderAuth }
</AuthContext.Consumer>
...
</AuthProvider>