mbas
March 5, 2024, 4:25pm
1
I am trying to get access token with the help of getAccessToken
method as mentioned here 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?
tyf
March 5, 2024, 10:08pm
3
Hey there @mbas welcome to the community!
I’m not super familiar with the nextjs-auth0
SDK but it looks you should be able to call getAccessToken
with no args:
opened 03:38PM - 17 Aug 23 UTC
closed 04:43PM - 21 Aug 23 UTC
question
### 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!
system
Closed
March 29, 2024, 10:43pm
4
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.