- Configure custom auth in the CDP Portal (JWKS endpoint, issuer, etc.)
- Provide a
customAuth.getJwtcallback in your CDP initialization config
Returns
authenticateWithJWT()
Returns
Promise<AuthenticateWithJWTResult>
function useAuthenticateWithJWT(): {
authenticateWithJWT: () => Promise<AuthenticateWithJWTResult>;
};
customAuth.getJwt callback in your CDP initialization config{
authenticateWithJWT: () => Promise<AuthenticateWithJWTResult>;
}
authenticateWithJWT: () => Promise<AuthenticateWithJWTResult>;
Promise<AuthenticateWithJWTResult>
// React - With Auth0
import { useAuth0 } from '@auth0/auth0-react';
import { useAuthenticateWithJWT } from '@coinbase/cdp-hooks';
function AuthButton() {
const { getAccessTokenSilently } = useAuth0();
const { authenticateWithJWT } = useAuthenticateWithJWT();
const [error, setError] = useState(null);
const handleLogin = async () => {
try {
// Authenticate with CDP (uses customAuth.getJwt callback)
const { user, isNewUser } = await authenticateWithJWT();
console.log('Authenticated user:', user);
if (isNewUser) {
console.log('New user created with wallet!');
}
} catch (err) {
setError(err.message);
}
};
return (
<div>
<button onClick={handleLogin}>Sign In with Auth0</button>
{error && <p>Error: {error}</p>}
</div>
);
}
// React Native - With Auth0
import { useAuth0 } from 'react-native-auth0';
import { useAuthenticateWithJWT } from '@coinbase/cdp-hooks';
import { Button, Text, View } from 'react-native';
function AuthScreen() {
const { authorize } = useAuth0();
const { authenticateWithJWT } = useAuthenticateWithJWT();
const [error, setError] = useState(null);
const handleLogin = async () => {
try {
// Step 1: Trigger Auth0 login (opens browser)
await authorize();
// Step 2: Authenticate with CDP
const { user, isNewUser } = await authenticateWithJWT();
console.log('Authenticated user:', user);
if (isNewUser) {
console.log('New user created with wallet!');
}
} catch (err) {
setError(err.message);
}
};
return (
<View>
<Button title="Sign In with Auth0" onPress={handleLogin} />
{error && <Text>Error: {error}</Text>}
</View>
);
}
Was this page helpful?