# How to use a post-login event

**URL:** <https://community.auth0.com/t/how-to-use-a-post-login-event/103766>\
**Category:** Get Help\
**Tags:** classic-universal-login-experience, login-experience\
**Created:** [March 30, 2023, 3:30pm UTC](https://community.auth0.com/t/how-to-use-a-post-login-event/103766 "2023-03-30T15:30:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![karen2](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/karen2/32/45101_2.png) [@karen2](https://community.auth0.com/u/karen2)\
**Post date:** [March 30, 2023, 3:30pm UTC](https://community.auth0.com/t/how-to-use-a-post-login-event/103766/1 "2023-03-30T15:30:40Z")

</div>

I would like to trigger a programmatic event on my React application,  
I saw on the doc it is possible to use a [post-login event](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow/event-object), which is exactly what I am looking for.  
My question: is it implemented out-of-the-box by the [library auth0 for react](https://github.com/auth0/auth0-react)?  
As of today I’m using the last version `2.0.1`  
Here is a code sample that could add some context:

```typescript
import React, { ReactNode } from "react";
import { useNavigate } from "react-router-dom";
import { Auth0Provider, AppState } from "@auth0/auth0-react";
interface Props {
  children: ReactNode;
}
function Auth0ProviderWithHistory({ children }: Props) {
  const domain = process.env.REACT_APP_AUTH0_DOMAIN;
  const clientId = process.env.REACT_APP_AUTH0_CLIENT_ID;
  const audience = process.env.REACT_APP_API_AUDIENCE;
  const navigate = useNavigate();
  const onRedirectCallback = (appState?: AppState) => {
    navigate(
      appState?.returnTo || window.location.pathname + window.location.search
    );
  };
  return (
    <Auth0Provider
      domain={domain}
      clientId={clientId}
      onRedirectCallback={onRedirectCallback}
      authorizationParams={{
        redirect_uri: window.location.origin,
        audience: audience
      }}
     // postLoginTriggerEvent={(event) => {triggerAnalytics(event)}} Is what I am looking for
    >
      {children}
    </Auth0Provider>
  );
}
export default Auth0ProviderWithHistory;

```

The function `onRedirectCallback` is not good enough because triggered not only after a user log in but also when he is already logged in and reload the application.

---

<div class="post-metadata">

**Author:** ![gparascandolo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gparascandolo/32/38788_2.png) [@gparascandolo](https://community.auth0.com/u/gparascandolo)\
**Post date:** [March 30, 2023, 3:57pm UTC](https://community.auth0.com/t/how-to-use-a-post-login-event/103766/3 "2023-03-30T15:57:49Z")

</div>

Hi @karen2, Post-Login Action events occur as part of the authorization flow on the Auth0 backend when a user logs in to any application in an Auth0 tenant.

In other words, you do not have to pass in any parameter in `Auth0Provider` to initiate the Post-Login Action, it will automatically trigger when users logs into your application.

> The function `onRedirectCallback` is not good enough because triggered not only after a user log in but also when he is already logged in and reload the application.

I want to note that Post-Login Actions occur not only for logins, but also for silent authentication + refresh\_token rotation requests (which sounds like the issue you are mentioning).

You can ignore these types of silent auth + refresh\_token rotation requests in the Auth0 Action by doing something like below in the following code snippet:

```auto
exports.onExecutePostLogin = async (event, api) => {

  // refresh token rotation or a silent auth request
  const is_silent_auth = event.transaction?.protocol === 'oauth2-refresh-token' ||
                         event.request.query?.prompt === 'none';
  if (is_silent_auth) return;

  // continue your code here
}

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [December 12, 2024, 8:07am UTC](https://community.auth0.com/t/how-to-use-a-post-login-event/103766/4 "2024-12-12T08:07:59Z")

</div>

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