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
Hi
I am new to nextjs and authjs. I am reading the doc, I have successfully integrated a nexjs app with keycloak, I am able to login and obtain user info, as explained in the getting started guide.
Now I am trying to access a private rest endpoint running on my machine, also secured with keycloak, using the following code
import{auth}from"@/auth"asyncfunctiongetData(){constres=awaitfetch('http://127.0.0.1:8180/customers');if(!res.ok){returnnull;}returnres.json();}exportdefaultasyncfunctionPage(){const{ user }=awaitauth();constdata=awaitgetData();return(<><p>Hello{user?.name}</p><p>Data: {JSON.stringify(data)}</p></>);}
But from the http trace on the API log I can see no token is attached to the request header. I am sure I am missing something on how all that works, but can you please help me undestrand how this should work? After I correctly log in, how should I make secure API calls using authjs and nextjs to fetch data ?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi
I am new to nextjs and authjs. I am reading the doc, I have successfully integrated a nexjs app with keycloak, I am able to login and obtain user info, as explained in the getting started guide.
Now I am trying to access a private rest endpoint running on my machine, also secured with keycloak, using the following code
But from the http trace on the API log I can see no token is attached to the request header. I am sure I am missing something on how all that works, but can you please help me undestrand how this should work? After I correctly log in, how should I make secure API calls using authjs and nextjs to fetch data ?
Beta Was this translation helpful? Give feedback.
All reactions