You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my Nuxt application, I am making an internal server-side fetch request from one API route to another using $fetch In-Server fetch. The API being called /api/collectionItems uses requireUserSession(event) to retrieve the authenticated user’s secure ID. However, despite having a valid session in the initial request, requireUserSession(event) returns undefined, leading to a 401 Unauthorized error.
exportdefaultcatchEventHandler(asyncevent=>{const{ secure }=awaitrequireUserSession(event)// Secure user ID is undefinedawaitcreateCollectionItems(data,secure.userId)return{statusCode: 201,message: `Collection items created successfully`}})
Expected Behavior
The session information, including secure.userId, should persist when making the internal request.
requireUserSession(event) should return the authenticated user’s ID in collectionItem.post.ts.
Actual Behavior
secure.userId is undefined inside collectionItem.post.ts, causing a 401 Unauthorized error.
Should I explicitly forward session cookies when making the internal $fetch request?
Does requireUserSession require additional configuration for in-server API calls?
Is there a recommended approach to persist authentication across internal fetch requests?
The text was updated successfully, but these errors were encountered:
In my Nuxt application, I am making an internal server-side fetch request from one API route to another using $fetch In-Server fetch. The API being called
/api/collectionItems
uses requireUserSession(event) to retrieve the authenticated user’s secure ID. However, despite having a valid session in the initial request, requireUserSession(event) returns undefined, leading to a 401 Unauthorized error.Requesting API (index.ts)
collectionItem.post.ts
Expected Behavior
Actual Behavior
secure.userId is undefined inside collectionItem.post.ts, causing a 401 Unauthorized error.
Should I explicitly forward session cookies when making the internal $fetch request?
Does requireUserSession require additional configuration for in-server API calls?
Is there a recommended approach to persist authentication across internal fetch requests?
The text was updated successfully, but these errors were encountered: