# How to check whether user authorized or not when onChange of route event in kibana 7.8 OSS version

**URL:** <https://discuss.elastic.co/t/how-to-check-whether-user-authorized-or-not-when-onchange-of-route-event-in-kibana-7-8-oss-version/247265>\
**Category:** Kibana\
**Created:** [September 2, 2020, 5:06pm UTC](https://discuss.elastic.co/t/how-to-check-whether-user-authorized-or-not-when-onchange-of-route-event-in-kibana-7-8-oss-version/247265 "2020-09-02T17:06:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jayanth\_Mogadampalli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jayanth_mogadampalli/32/74602_2.png) [@Jayanth\_Mogadampalli](https://discuss.elastic.co/u/Jayanth_Mogadampalli)\
**Post date:** [September 2, 2020, 5:06pm UTC](https://discuss.elastic.co/t/how-to-check-whether-user-authorized-or-not-when-onchange-of-route-event-in-kibana-7-8-oss-version/247265/1 "2020-09-02T17:06:34Z")

</div>

Right now, I am using elastic/kibana 7.8 OSS version code  
I am trying to implement authentication using Google auth by developing a plugin.  
**Now for protecting routes, how to listen to route changes in kibana from a plugin**  
for detecting route change we implemented that in following way by adding **isAuth()** in src/core/public/application/app\_router.tsx file:

```
     {[...mounters]
      // legacy apps can have multiple sub-apps registered with the same route
      // which needs additional logic that is handled in the catch-all route below
      .filter(([_, mounter]) => !mounter.legacy)
      .map(([appId, mounter]) => (
        <Route
          key={mounter.appRoute}
          path={mounter.appRoute}
          render={({ match: { url } }) =>
            isAuth() ? (
              <AppContainer
                appPath={url}
                appStatus={appStatuses.get(appId) ?? AppStatus.inaccessible}
                createScopedHistory={createScopedHistory}
                {...{ appId, mounter, setAppLeaveHandler, setIsMounting }}
              />
            ) : (
              <Redirect to="/app/auth" />
            )
          }
        />
      ))}

```

But even when user is not logged in by checking with isAuth() it is not directing to /auth route  
Can anybody help me to solve this issue or provide code for authorization of routes!

---

<div class="post-metadata">

**Author:** ![rashmi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rashmi/32/16391_2.png) [@rashmi](https://discuss.elastic.co/u/rashmi)\
**Post date:** [September 4, 2020, 5:48am UTC](https://discuss.elastic.co/t/how-to-check-whether-user-authorized-or-not-when-onchange-of-route-event-in-kibana-7-8-oss-version/247265/2 "2020-09-04T05:48:26Z")

</div>

cc @Larry_Gregory might know the answer - he will shed some light when he gets a chance

Thanks  
Rashmi

---

<div class="post-metadata">

**Author:** ![Jayanth\_Mogadampalli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jayanth_mogadampalli/32/74602_2.png) [@Jayanth\_Mogadampalli](https://discuss.elastic.co/u/Jayanth_Mogadampalli)\
**Post date:** [September 4, 2020, 7:20am UTC](https://discuss.elastic.co/t/how-to-check-whether-user-authorized-or-not-when-onchange-of-route-event-in-kibana-7-8-oss-version/247265/3 "2020-09-04T07:20:52Z")

</div>

Every route enters isAuth() function before displaying component in that route  
But while routing to '/app/kibana', it is not entering isAuth() before rendering the component  
Where to authorize '/app/kibana' path before rendering the component

---

<div class="post-metadata">

**Author:** ![Larry\_Gregory](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/larry_gregory/32/34969_2.png) [@Larry\_Gregory](https://discuss.elastic.co/u/Larry_Gregory)\
**Post date:** [September 8, 2020, 10:53am UTC](https://discuss.elastic.co/t/how-to-check-whether-user-authorized-or-not-when-onchange-of-route-event-in-kibana-7-8-oss-version/247265/4 "2020-09-08T10:53:24Z")

</div>

It looks like the core `application` service exposes an Observable of the current application id via `core.application.currentAppId$`. You can use this to listen for app changes, and if that happens, run your own code.

If you need to redirect, you can then use the `core.application.navigateToUrl` or `core.application.navigateToApp` to send the user to your own auth page.

I must warn you though, that enforcing authentication and authorization via client-side mechanisms **is not a secure approach**. A much better approach would be to implement this on both the client and server side in order to enforce access control. The scope if that work isn't something I can help you with over the discussion boards, but I can help answer any direct questions in followup posts.

---

<div class="post-metadata">

**Author:** ![Jayanth\_Mogadampalli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jayanth_mogadampalli/32/74602_2.png) [@Jayanth\_Mogadampalli](https://discuss.elastic.co/u/Jayanth_Mogadampalli)\
**Post date:** [September 8, 2020, 11:37am UTC](https://discuss.elastic.co/t/how-to-check-whether-user-authorized-or-not-when-onchange-of-route-event-in-kibana-7-8-oss-version/247265/5 "2020-09-08T11:37:32Z")

</div>

> [@Larry\_Gregory](#):
>
> . You can use this to listen for app changes

We are looking to authenticate routes based on cookie, what is the best approach to do ?  
In which file in kibana we can listen to on route change or do authentication onRoute change?

---

<div class="post-metadata">

**Author:** ![vvvprabhakar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vvvprabhakar/32/53806_2.png) [@vvvprabhakar](https://discuss.elastic.co/u/vvvprabhakar)\
**Post date:** [September 8, 2020, 11:41am UTC](https://discuss.elastic.co/t/how-to-check-whether-user-authorized-or-not-when-onchange-of-route-event-in-kibana-7-8-oss-version/247265/6 "2020-09-08T11:41:35Z")

</div>

Even i looking for something like this .  
Whenever i click on any link or try to navigate to any route i want to have a check for that route , I am using OSS and i want this functionality across the app

Which place to do it ?  
Its like check on reach route, before navigate to that route  
Any help

---

<div class="post-metadata">

**Author:** ![vvvprabhakar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vvvprabhakar/32/53806_2.png) [@vvvprabhakar](https://discuss.elastic.co/u/vvvprabhakar)\
**Post date:** [September 8, 2020, 11:45am UTC](https://discuss.elastic.co/t/how-to-check-whether-user-authorized-or-not-when-onchange-of-route-event-in-kibana-7-8-oss-version/247265/7 "2020-09-08T11:45:23Z")

</div>

Or a common place across the routes, onroutechange start which used to be in previous version of kibana  
i want a place where i can call a function on every route change

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 6, 2020, 11:45am UTC](https://discuss.elastic.co/t/how-to-check-whether-user-authorized-or-not-when-onchange-of-route-event-in-kibana-7-8-oss-version/247265/8 "2020-10-06T11:45:25Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
