etn-ccis/blui-angular-workflows

Add option to set ON_AUTHENTICATED route

Closed this issue · 2 comments

Describe the desired behavior

Default ON_AUTHENTICATED route not always populated.

If a user has an application where the PxbAuthSecurityService is not constructed before routing to a user's auth component, the ON_AUTHENTICATED route wont be set correctly.

This service has logic that inspects the url before navigating to the auth component and saves the intended route (e.g. page-one, page-two, etc) it so the user can be directed to the correct screen after login.

Describe the desired behavior

Add a function call that can be invoked in AppComponent that reliably populates ON_AUTHENTICATED route.

//This only works if the PxbSecurityStateService is loaded on AppComponent init.  Can be transitive.  

// Whenever the application loads for the first time, we may want to direct the user to their original destination, before they were redirected to the login screen.
    constructor(private readonly _router: Router, private readonly _pxbAuthConfig: PxbAuthConfig) {
        _router.events.subscribe((event) => {
            if (event instanceof NavigationStart && !this.isFirstRouteCaptured) {
                this.isFirstRouteCaptured = true;
                const url = event.url;
                // If the initial route loaded is not part of the auth workflow, make it so authenticated users will redirect to it post-login.
                if (
                    !matchesRoute(url, 'LOGIN') &&
                    !matchesRoute(url, 'CONTACT_SUPPORT') &&
                    !matchesRoute(url, 'CREATE_ACCOUNT') &&
                    !matchesRoute(url, 'CREATE_ACCOUNT_INVITE') &&
                    !matchesRoute(url, 'FORGOT_PASSWORD') &&
                    !matchesRoute(url, 'RESET_PASSWORD') &&
                    !matchesRoute(url, 'AUTH_WORKFLOW')
                ) {
                    AUTH_ROUTES.ON_AUTHENTICATED = event.url;
                }
            }
        });
    }

Encourage users to call this ON_AUTHENTICATED route setting method on App load. Update example app, docs, and service to contain new method and call.