Log user out of okta if is not authorised in my application

Hello! Does anyone know of a way that I could log a user out of okta if it has no authorization to access my application? I don’t really want to redirect them to okta and then again to my page because I want to show him an error message, that gets lost in the redirects. Can anyone help me with this? Thank you!