# Action Flow AccessToken empty on onExecutePostLogin

**URL:** <https://community.auth0.com/t/action-flow-accesstoken-empty-on-onexecutepostlogin/109392>\
**Category:** Get Help\
**Tags:** login-experience, new-universal-login-experience\
**Created:** [June 16, 2023, 11:58am UTC](https://community.auth0.com/t/action-flow-accesstoken-empty-on-onexecutepostlogin/109392 "2023-06-16T11:58:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nolafs](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nolafs/32/47696_2.png) [@nolafs](https://community.auth0.com/u/nolafs)\
**Post date:** [June 16, 2023, 11:58am UTC](https://community.auth0.com/t/action-flow-accesstoken-empty-on-onexecutepostlogin/109392/1 "2023-06-16T11:58:06Z")

</div>

Hi,

I have 4 action on my login flow. The first action has no issue accessing access api.accessToken but my last action, all api values are empty. Why?

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

  const axios = require("axios").default;
  
  const accessToken = api.accessToken;
  const user = {
    email: event.user.email,
    auth0Id: event.user.user_id
  }  

```

Event object is fine.

Cheers  
Olaf

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [June 16, 2023, 6:42pm UTC](https://community.auth0.com/t/action-flow-accesstoken-empty-on-onexecutepostlogin/109392/3 "2023-06-16T18:42:54Z")

</div>

Hi @nolafs,

Thanks for reaching out to the Auth0 Community!

Could you please use the Actions debugger interface to test your last Action script to see if there are any errors or unexpected results?

If not, could you please share your last Action script and clarify if you are trying to set a custom claim to the access token?

The current script you shared has variables assigned but unused.

I look forward to your update.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![nolafs](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nolafs/32/47696_2.png) [@nolafs](https://community.auth0.com/u/nolafs)\
**Post date:** [June 19, 2023, 7:30am UTC](https://community.auth0.com/t/action-flow-accesstoken-empty-on-onexecutepostlogin/109392/4 "2023-06-19T07:30:55Z")

</div>

Hi Rueben,

Sure, the access token is empty. Here are my test results:

 ![test](https://global.discourse-cdn.com/auth0/original/3X/2/5/2511c551ec6ab2242be7f028483d7cac5d1046aa.png)

thanks

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [June 23, 2023, 5:45pm UTC](https://community.auth0.com/t/action-flow-accesstoken-empty-on-onexecutepostlogin/109392/5 "2023-06-23T17:45:38Z")

</div>

Hi @nolafs,

Thanks for the update and clarification.

The result you observed is expected. The correct usage for the `api.accessToken` is to set a custom claim like the following syntax:

```auto
api.accessToken.setCustomClaim(name, value)

```

(Reference: [Actions Triggers: post-login - API Object](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow/api-object#:~:text=api.accessToken.setCustomClaim(name%2C%20value)))

I would also like to add that the API Object provides methods for changing the behavior of the flow and cannot be used to read data. This means that you won’t be able to get the data from the access token until you have completed the login flow.

 ![image](https://global.discourse-cdn.com/auth0/original/3X/5/0/50c2c38d8eb038537d6d890fb3801f2a298f77ed.png)  
(Reference: [Login Flow](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow#:~:text=in%20via%20Auth0.-,API%20object,%3A%20Provides%20methods%20for%20changing%20the%20behavior%20of%20the%20flow.,-Common%20use%20cases))

Please let me know if you have any questions.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![nolafs](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nolafs/32/47696_2.png) [@nolafs](https://community.auth0.com/u/nolafs)\
**Post date:** [June 26, 2023, 7:05am UTC](https://community.auth0.com/t/action-flow-accesstoken-empty-on-onexecutepostlogin/109392/6 "2023-06-26T07:05:29Z")

</div>

Ok, I understand but I do need to be able to call my api during the flow, how do I protect those endpoints?

---

<div class="post-metadata">

**Author:** ![nolafs](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nolafs/32/47696_2.png) [@nolafs](https://community.auth0.com/u/nolafs)\
**Post date:** [June 26, 2023, 5:12pm UTC](https://community.auth0.com/t/action-flow-accesstoken-empty-on-onexecutepostlogin/109392/7 "2023-06-26T17:12:08Z")

</div>

How do i protect my api then?

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [June 27, 2023, 6:46pm UTC](https://community.auth0.com/t/action-flow-accesstoken-empty-on-onexecutepostlogin/109392/8 "2023-06-27T18:46:24Z")

</div>

Hi @nolafs,

Thanks for following up.

You can protect your endpoints with [Scopes](https://auth0.com/docs/get-started/apis/scopes/api-scopes) (permissions).

It would look something like the following:

```auto
https://{yourDomain}/authorize?
    response_type=code&
    client_id={yourClientId}&
    redirect_uri={https://yourApp/callback}&
    scope=email%20profile%20openid%20read:reports%20update:reports&
    audience={yourAPIAudience}&
    state={state}

```

(Reference: [Call Your API Using the Authorization Code Flow](https://auth0.com/docs/get-started/authentication-and-authorization-flow/call-your-api-using-the-authorization-code-flow))

So say, for example, if a user does not have permissions granted to them, that are required for accessing your app or some protected resource, then they will be prevented from logging in.

Here are some helpful resources:

- [Sample Use Cases: Scopes and Claims](https://auth0.com/docs/get-started/apis/scopes/sample-use-cases-scopes-and-claims)
- [How do I assign Permissions to users?](https://community.auth0.com/t/how-do-i-assign-permissions-to-users/72278)

Please let me know how this goes for you.

Thanks,  
Rueben

---

<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:** [July 11, 2023, 6:47pm UTC](https://community.auth0.com/t/action-flow-accesstoken-empty-on-onexecutepostlogin/109392/9 "2023-07-11T18:47:17Z")

</div>

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