Angular Sign-in widget - Check if user is already authenticated

I am developing an application in Angular using the Okta Sign-In widget. The logic for accepting a user response is below:

ngOnInit() {

    this.widget.renderEl(
      {
        el: '#okta-signin-container',
      },
      (res) => {
        if (res.status === 'SUCCESS') {
          this.signIn.loginRedirect('/dashboard', {
            sessionToken: res.session.token,
          });
          // Hide the widget
          this.widget.hide();
        }
      },
      (err) => {
        throw err;
      }
    );
  }

I want to introduce a check in the logic that prevents a log-in and displays a login if a user is already logged in (a valid session exists). This user would have been logged in from another method while the page with the widget has already been loaded. This would look something like below with a dummy isAuthenticated() method:

ngOnInit() 
{
    this.widget.renderEl(
    {
        el: '#okta-signin-container',
    },
    (res) => {
        if (res.status === 'SUCCESS') {
            // If user is already logged in
            if(isAuthenticated())
            {
                // Display a pop-up and prevent login
            }
            else
            {
                sessionToken: res.session.token,
            }
            this.signIn.loginRedirect('/dashboard', {
          });
          // Hide the widget
          this.widget.hide();
        }
      },
      (err) => {
        throw err;
      }
    );
}

Is this possible? Please let me know if I need to clarify anything or add any extra information :slight_smile:

Package versions:
@okta/okta-angular: 2.2.1
@okta/okta-signin-widget: 5.16.1

The full code for this section is as below:

signIn;

widget = new OktaSignIn({
    baseUrl: '{OKTA_URL}',
    registration: {
      click: function () {
        window.location.href = '/sign-ups';
      },
    },
    features: {
      registration: true,
    },
    authParams: {
      pkce: true,
    },
  });

constructor(oktaAuthService: OktaAuthService,
              router: Router,
              private actvRoute: ActivatedRoute)
  {
    this.signIn = oktaAuthService;

    // Show the widget when prompted, otherwise remove it from the DOM.
    router.events.forEach((event) => {
      if (event instanceof NavigationStart) {
        switch (event.url) {
          case '/login':
            break;
          case '/protected':
            break;
          default:
            this.widget.remove();
            break;
        }
      }
    });
  }

  ngOnInit() {

    this.widget.renderEl(
      {
        el: '#okta-signin-container',
      },
      (res) => {
        if (res.status === 'SUCCESS') {
          this.signIn.loginRedirect('/dashboard', {
            sessionToken: res.session.token,
          });
          // Hide the widget
          this.widget.hide();
        }
      },
      (err) => {
        throw err;
      }
    );
  }