# getAccessToken requires req and res parameters

**URL:** <https://community.auth0.com/t/getaccesstoken-requires-req-and-res-parameters/128976>\
**Category:** Get Help\
**Tags:** apis, application\
**Created:** [March 5, 2024, 4:25pm UTC](https://community.auth0.com/t/getaccesstoken-requires-req-and-res-parameters/128976 "2024-03-05T16:25:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbas](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mbas/32/48606_2.png) [@mbas](https://community.auth0.com/u/mbas)\
**Post date:** [March 5, 2024, 4:25pm UTC](https://community.auth0.com/t/getaccesstoken-requires-req-and-res-parameters/128976/1 "2024-03-05T16:25:24Z")

</div>

I am trying to get access token with the help of `getAccessToken` method as mentioned [here](https://auth0.github.io/nextjs-auth0/types/session_get_access_token.GetAccessToken.html) in the `@auth0/nextjs-auth0` documents. It shows as if there is no need to pass the `req` and `res` parameters when using in a “page” or “React Server Component” but without `req` and `res` parameters it does not work. Could you clarify this matter? Is it really possible to use `getAccessToken` method without passing `req` and `res` parameters as in the documents? If so, how?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [March 5, 2024, 10:08pm UTC](https://community.auth0.com/t/getaccesstoken-requires-req-and-res-parameters/128976/3 "2024-03-05T22:08:31Z")

</div>

Hey there @mbas welcome to the community!

> [@mbas](#):
>
> Is it really possible to use `getAccessToken` method without passing `req` and `res` parameters as in the documents? If so, how?

I’m not _super_ familiar with the `nextjs-auth0` SDK but it looks you should be able to call `getAccessToken` with no args:

> <https://github.com/auth0/nextjs-auth0/issues/1372#issuecomment-1683567343>
>
> \### Checklist
> 
> \- \[X\] I have looked into the \[Readme\](https://github.com/auth0/ne…xtjs-auth0#readme), \[Examples\](https://github.com/auth0/nextjs-auth0/blob/main/EXAMPLES.md), and \[FAQ\](https://github.com/auth0/nextjs-auth0/blob/main/FAQ.md) and have not found a suitable solution or answer.
> \- \[X\] I have looked into the \[API documentation\](https://auth0.github.io/nextjs-auth0/) and have not found a suitable solution or answer.
> \- \[X\] I have searched the \[issues\](https://github.com/auth0/nextjs-auth0/issues) and have not found a suitable solution or answer.
> \- \[X\] I have searched the \[Auth0 Community\](https://community.auth0.com) forums and have not found a suitable solution or answer.
> \- \[X\] I agree to the terms within the \[Auth0 Code of Conduct\](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md).
> 
> \### Describe the problem you'd like to have solved
> 
> We're looking to migrate to the new app directory. Currently, we use \`getServerSideProps\` and its \[context\](https://nextjs.org/docs/pages/api-reference/functions/get-server-side-props) parameter to access the \`req\` and \`res\` needed to call this library's \`getAccessToken\` function in order to make authenticated API calls to another Auth0-protected application. Using the new server components, we'll need to drop \`getServerSideProps\` for \`fetch\`es directly in the components themselves. We'll still need to use \`getAccessToken\` though to authenticate the requests. What I can't understand is how we can use \`getAccessToken\` when there's no longer access to the \`context.req\` (\`NextApiRequest\`) and \`context.res\` (\`NextApiResponse\`) objects.
> 
> It seems we might need a new method in this library which accepts the required headers using https://nextjs.org/docs/app/api-reference/functions/headers#headers?
> 
> \### Describe the ideal solution
> 
> Be able to call \`getAccessToken\` from a server component.
> 
> \### Alternatives and current workarounds
> 
> \_No response\_
> 
> \### Additional context
> 
> Thanks a lot!

---

<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:** [March 29, 2024, 10:43pm UTC](https://community.auth0.com/t/getaccesstoken-requires-req-and-res-parameters/128976/4 "2024-03-29T22:43:08Z")

</div>

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