Overview
In some cases, a user’s access may need to be filtered according to certain conditions. This article explains how to filter users and redirect them to a specific error or message page, depending on the use case.
Applies To
- Actions
- Login Flow
Solution
If multiple applications are used, one way to application-specific error pages is to configure the tenant to redirect to a custom error page. In this case, the Authorization Server will include the application’s client_id
parameter appended to the query string.
Please consider that a log-out cal l will be required before the redirect.
A conditional statement within the action can also be used to send the user to the error page that corresponds with the application’s client_id
. Using the specific client_id
, users can also be redirected back to the login page.
See the following possible example of redirecting users back to the original login page after they have been logged out:
exports.onExecutePostLogin = async (event, api) => {
//retrieve the client_id of the application
let client=event.client.client_id
let logout_url='https://[your_domain]/v2/logout?client_id='
let login_url='https://[your_domain]/authorize?response_type=code&client_id='
if ([your_condition]) {
//if the condition is met, trigger the logout
api.redirect.sendUserTo(logout_url+client, {
//redirect the user after logout back to login or to a custom page
query: { returnTo: login_url+client }
// query: { returnTo: 'custom_error_page_URL' }
});
};
}