Hooks
useExternalAuth
This is an enterprise-only feature. Please contact us if you are interested.
You must update your SDK version to v3.0.0-alpha.6 or above for this feature
Summary
This hook provides a way for clients to sign-in to Dynamic or link with Dynamic using a third-party issued JWT auth token.
The hook needs to be initialized within a child of DynamicContextProvider.
Usage
Available methods:
signInWithExternalJwt
: Sign in to Dynamic by providing the external user ID and JWT. This will automatically set the logged-in Dynamicuser
when successful.verifyWithExternalJwt
: Verify and link an external user in Dynamic by providing the external user ID and JWT.
Usage
const { signInWithExternalJwt, verifyWithExternalJwt } = useExternalAuth();
try {
// `externalUserId`: User ID in the external auth system
// `externalJwt`: Raw encoded JWT issued by external auth system
const userProfile = await signInWithExternalJwt({
externalUserId,
externalJwt
});
if (userProfile) {
// You should be logged in at this point
}
} catch (e: any) {
console.error('Dynamic login failed:', e);
}
try {
const verifiedProfile = await verifyWithExternalJwt({
externalUserId,
externalJwt
});
if (verifiedProfile) {
// User verification successful
}
} catch (e: any) {
console.error('Dynamic verification failed:', e);
}
Details
In order to use this hook, the proper Third-Party Auth settings need to be configured.
Was this page helpful?