# Post-login redirect-with-actions doesn't work, please tell me how to execute this correctly

**URL:** <https://community.auth0.com/t/post-login-redirect-with-actions-doesnt-work-please-tell-me-how-to-execute-this-correctly/65183>\
**Category:** Get Help\
**Tags:** aws-lambda, login, auth0\
**Created:** [June 28, 2021, 9:24am UTC](https://community.auth0.com/t/post-login-redirect-with-actions-doesnt-work-please-tell-me-how-to-execute-this-correctly/65183 "2021-06-28T09:24:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![endo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/endo/32/30254_2.png) [@endo](https://community.auth0.com/u/endo)\
**Post date:** [June 28, 2021, 9:24am UTC](https://community.auth0.com/t/post-login-redirect-with-actions-doesnt-work-please-tell-me-how-to-execute-this-correctly/65183/1 "2021-06-28T09:24:39Z")

</div>

> **[Login Flow](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow)**
>
> Learn about the Actions Login Flow and the post-login Action trigger, which is executed after a user logs in and when a Refresh Token is requested.

> **[Redirect with Actions](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow/redirect-with-actions)**
>
> Learn how to use post-login Actions to redirect users before an authentication transaction is complete.

With reference to this, we are implementing an implementation that redirects to another server at login and performs additional login processing.  
I was able to pass user information and redirect with api.redirect.sendUserTo,  
When I redirect to Auth0 Application again with https: // YOUR\_DOMAIN / continue? State = THE\_ORIGINAL\_STATE, I get an Unauthorized error with Request failed with status code 401.

YOUR\_DOMAIN → Domain automatically generated by Auth0 applications  
THE\_ORIGINAL\_STATE → value of state parameter automatically assigned when redirecting api.redirect.sendUserTo

I tried both the GET and POST methods, but the redirection didn’t work.

Is there anything wrong with it, and I would like to know what to do in order for the redirection to take place and authentication to complete successfully.  
Also, shouldn’t I return any response when redirecting to my server by api.redirect.sendUserTo, or should I redirect at https: // YOUR\_DOMAIN / continue without worrying about it?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [June 28, 2021, 10:06pm UTC](https://community.auth0.com/t/post-login-redirect-with-actions-doesnt-work-please-tell-me-how-to-execute-this-correctly/65183/3 "2021-06-28T22:06:57Z")

</div>

Hi @endo,

Welcome to the Community!

Can you post the entire error? There should be a more detailed message that will help us understand why the request is unauthorized.

---

<div class="post-metadata">

**Author:** ![endo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/endo/32/30254_2.png) [@endo](https://community.auth0.com/u/endo)\
**Post date:** [July 3, 2021, 7:15am UTC](https://community.auth0.com/t/post-login-redirect-with-actions-doesnt-work-please-tell-me-how-to-execute-this-correctly/65183/4 "2021-07-03T07:15:46Z")

</div>

thanks to reply, dan!

entire error is below.

```plaintext
{
  "message":"Request failed with status code 401",
  "name":"Error",
  "stack":"
    Error: Request failed with status code 401
    at createError (/var/task/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/var/task/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/var/task/node_modules/axios/lib/adapters/http.js:260:11)
    at IncomingMessage.emit (events.js:388:22)
    at endReadableNT (internal/streams/readable.js:1336:12)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
  ",
  "config":{
    "url":"https://my-app.jp.auth0.com/continue",
    "method":"post",
    "data":"{
      "isSuccess":false,
      "token":"${JWT token}",
      "state":"hKFo2SBXZkJzeWlha0YwMk1YNGROVDF5Mk9neC1GZXF1ZjVNNKFuqHJlZGlyZWN0o3RpZNkgMkw4cS1ra2QtcjFnczAtRjJtWm0tc3pELXh4NEQ2REGjY2lk2SBoTXJURXloWFJQN1dLZ3puYllsbUU3elUyVFkzdEZ1NQ",
      "headers":{
        "Accept":"application/json, text/plain, */*",
        "Content-Type":"application/json",
        "x-hasura-admin-secret":"${hasura secret}",
        "User-Agent":"axios/0.21.1",
        "Content-Length":687
      },
      "params":{
        "state":"hKFo2SBXZkJzeWlha0YwMk1YNGROVDF5Mk9neC1GZXF1ZjVNNKFuqHJlZGlyZWN0o3RpZNkgMkw4cS1ra2QtcjFnczAtRjJtWm0tc3pELXh4NEQ2REGjY2lk2SBoTXJURXloWFJQN1dLZ3puYllsbUU3elUyVFkzdEZ1NQ"
      },
      "transformRequest":[null],
      "transformResponse":[null],
      "timeout":0,
      "xsrfCookieName":"XSRF-TOKEN",
      "xsrfHeaderName":"X-XSRF-TOKEN",
      "maxContentLength":-1,
      "maxBodyLength":-1
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [July 6, 2021, 12:43pm UTC](https://community.auth0.com/t/post-login-redirect-with-actions-doesnt-work-please-tell-me-how-to-execute-this-correctly/65183/5 "2021-07-06T12:43:29Z")

</div>

@endo,

Can you please also post the code you use to resume authentication (the redirect to the `/continue` endpoint)?

---

<div class="post-metadata">

**Author:** ![igorg](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/igorg/32/33679_2.png) [@igorg](https://community.auth0.com/u/igorg)\
**Post date:** [December 22, 2021, 7:59am UTC](https://community.auth0.com/t/post-login-redirect-with-actions-doesnt-work-please-tell-me-how-to-execute-this-correctly/65183/7 "2021-12-22T07:59:19Z")

</div>

HI.  
I have the same 401 error  
Here is my Node server code:

```auto
import { Get, Query } from 'tsoa';
import axios from 'axios';

@Get('/stats')
public async stats(@Query() state: string, @Query() data: any) {

    const auth0Url = 'https://my-domain.us.auth0.com/continue?state=';

    try {
      const url = encodeURI(auth0Url + state);
      await axios(url);
    } catch (err) {
      console.log(err);
    }
    managementBL.storeLogin(data);
}

```

and this is error:

```auto
Error: Request failed with status code 401
    at createError (/node_modules/.pnpm/axios@0.21.0/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/node_modules/.pnpm/axios@0.21.0/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/node_modules/.pnpm/axios@0.21.0/node_modules/axios/lib/adapters/http.js:244:11)
    at IncomingMessage.emit (events.js:326:22)
    at endReadableNT (_stream_readable.js:1241:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  config: {
    url: 'https://my-domain.us.auth0.com/continue?state=hKFo2SBFNDYtVGFjYjE2NzdJMWt2UkRydXlfQzB6OVNrcnlheaFuqHJlZGlyZWN0o3RpZNkgVnpETTNvREJjMk11aDBBX2duZ1NPRENMNzhjR0J0NHSjY2lk2SBDR2ZaNnZHWE5mSGIxMThxcUVmbHdlVUhqMWt6MG9tUQ',
    headers: {
      Accept: 'application/json, text/plain, */*',
      'User-Agent': 'axios/0.21.0'
    },
    transformRequest: [[Function: transformRequest] ],
    transformResponse: [[Function: transformResponse] ],
    timeout: 0,
    adapter: [Function: httpAdapter],
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    validateStatus: [Function: validateStatus],
    method: 'get',
    data: undefined
  },
 _header: 'GET /continue?state=hKFo2SBFNDYtVGFjYjE2NzdJMWt2UkRydXlfQzB6OVNrcnlheaFuqHJlZGlyZWN0o3RpZNkgVnpETTNvREJjMk11aDBBX2duZ1NPRENMNzhjR0J0NHSjY2lk2SBDR2ZaNnZHWE5mSGIxMThxcUVmbHdlVUhqMWt6MG9tUQ HTTP/1.1\r\n' +
      'Accept: application/json, text/plain, */*\r\n' +
      'User-Agent: axios/0.21.0\r\n' +
      'Host: premera-getvim.us.auth0.com\r\n' +
      'Connection: close\r\n' +
      '\r\n',
_ended: true,
    res: IncomingMessage {
      _readableState: [ReadableState],
      readable: false,
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      socket: [TLSSocket],
      connection: [TLSSocket],
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      headers: [Object],
      rawHeaders: [Array],
      trailers: {},
      rawTrailers: [],
      aborted: false,
      upgrade: false,
      url: '',
      method: null,
      statusCode: 401,
      statusMessage: 'Unauthorized',
      client: [TLSSocket],
      _consuming: false,
      _dumped: false,
      req: [Circular],
      responseUrl: 'https://my-domain.us.auth0.com/continue?state=hKFo2SBFNDYtVGFjYjE2NzdJMWt2UkRydXlfQzB6OVNrcnlheaFuqHJlZGlyZWN0o3RpZNkgVnpETTNvREJjMk11aDBBX2duZ1NPRENMNzhjR0J0NHSjY2lk2SBDR2ZaNnZHWE5mSGIxMThxcUVmbHdlVUhqMWt6MG9tUQ',
      redirects: [],
      [Symbol(kCapture)]: false
    },

```

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [December 22, 2021, 10:30pm UTC](https://community.auth0.com/t/post-login-redirect-with-actions-doesnt-work-please-tell-me-how-to-execute-this-correctly/65183/8 "2021-12-22T22:30:31Z")

</div>

Are you using a social connection? I found a reference to this error where a user was returning this error as a result of using developer keys for their social connection.

---

<div class="post-metadata">

**Author:** ![pranshushah](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/pranshushah/32/34583_2.png) [@pranshushah](https://community.auth0.com/u/pranshushah)\
**Post date:** [February 1, 2022, 10:02am UTC](https://community.auth0.com/t/post-login-redirect-with-actions-doesnt-work-please-tell-me-how-to-execute-this-correctly/65183/9 "2022-02-01T10:02:40Z")

</div>

according to docs you should redirect to this URL not send the ajax request.

so for express write something like

```auto
	res.redirect(`https://domain.auth0.com/continue?state=${req.query.state}`);
 

```

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [February 3, 2022, 1:39pm UTC](https://community.auth0.com/t/post-login-redirect-with-actions-doesnt-work-please-tell-me-how-to-execute-this-correctly/65183/10 "2022-02-03T13:39:25Z")

</div>

Thanks for sharing that solution with others!

---

<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:** [February 18, 2022, 1:40pm UTC](https://community.auth0.com/t/post-login-redirect-with-actions-doesnt-work-please-tell-me-how-to-execute-this-correctly/65183/11 "2022-02-18T13:40:03Z")

</div>

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