The CustomizedConsent class implements the customized-consent screen functionality. This screen prompts the user to accept or deny the permissions and authorization details requested by a client application.
Create an instance of CustomizedConsent screen manager
Example
// How to use the CustomizedConsent screen SDK:import CustomizedConsent from '@auth0/auth0-acul-js/customized-consent';// Instantiate the manager for the customized consent screenconst consentManager = new CustomizedConsent();// Accessing screen dataconst clientName = consentManager.client.name;const userEmail = consentManager.user.email;const requestedScopes = consentManager.screen.scopes;const authorizationDetails = consentManager.screen.authorizationDetails;console.log(`${clientName} is requesting consent from ${userEmail}.`);console.log("Requested Scopes:", requestedScopes);console.log("Authorization Details:", authorizationDetails);// Accessing transaction errors from a previous attemptconst transactionErrors = consentManager.transaction.errors;if (transactionErrors && transactionErrors.length > 0) { transactionErrors.forEach(error => { console.error(`Error: ${error.message}`); // Display these errors to the user. });}// Example of handling consent acceptanceasync function onAcceptConsent() { try { await consentManager.accept(); // On success, Auth0 will typically redirect. } catch (e) { console.error('Failed to accept consent:', e); }}// Example of handling consent denialasync function onDenyConsent() { try { await consentManager.deny({ denial_reason: "user_declined" }); // On success, Auth0 will typically redirect. } catch (e) { console.error('Failed to deny consent:', e); }}
This method submits the user’s decision to accept the requested permissions and authorization details.
Example
import CustomizedConsent from '@auth0/auth0-acul-js/customized-consent';const consentManager = new CustomizedConsent();async function onAcceptConsent() { try { await consentManager.accept(); // On success, Auth0 will typically redirect. } catch (e) { console.error('Failed to accept consent:', e); }}
This method submits the user’s decision to deny the requested permissions and authorization details.
Example
import CustomizedConsent from '@auth0/auth0-acul-js/customized-consent';const consentManager = new CustomizedConsent();async function onDenyConsent() { try { await consentManager.deny({ denial_reason: "user_declined" }); // On success, Auth0 will typically redirect. } catch (e) { console.error('Failed to deny consent:', e); }}