Get session or accessToken inside a Helper class #2102
-
Question 💬Once you have the session, you can utilize the hooks useSession and getSession on various pages. I have a helper class which has all my API endpoints, and I need to get the accessToken from useSession (session object) but within the helper class I cannot use the hook. Is there some way to retrieve the session within the helper class without passing it in? Api.js
Yes, I can do Any ideas or is there some better approach? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can get the session by doing a fetch call to : https://next-auth.js.org/getting-started/rest-api#get-apiauthsession alternatively you can proxy your API requests through a Next.js API route and use either |
Beta Was this translation helpful? Give feedback.
You can get the session by doing a fetch call to :
/api/auth/session
https://next-auth.js.org/getting-started/rest-api#get-apiauthsession
alternatively you can proxy your API requests through a Next.js API route and use either
getSession
orgetToken
and attach the access token there before sending the request to your external api.