Not receiving the accessToken

Hello, when using const{ getAccessToken } = getKindeServerSession() and trying to get the accessToken I get any other thing beside a string with the token ( result attached). Please help. aud: [], azp: '', billing: { has_payment_details: false, org_entitlements: null, plan: { code: null, created_on: null, has_trial_period: null, invoice_due_on: null, name: null, plan_charge_type: null, trial_expires_on: null } }, exp: 1700955875, iat: 1700869475, iss: '', jti: '', scp: [ 'openid', 'profile', 'email', 'offline' ], sub: '', }
10 Replies
Sebastian Simionescu
i need the accessToken to send it to the backend I'm also open to any other sugestion on how can I send an authenticated request to the BE
Oli - Kinde
Oli - Kinde7mo ago
Hi @Sebastian Simionescu, Thanks for reaching out. What Kinde SDK are you using? And what version of the SDK are you using?
Sebastian Simionescu
I’m using next js sdk v2
Oli - Kinde
Oli - Kinde7mo ago
Hey @Sebastian Simionescu, Are you using the latest version of the Kinde NextJS SDK v2.0.10? We have made a lot of key updates on the NextJS SDK that may help you
Sebastian Simionescu
Hello @Oli - Kinde yes I do. Still getting the same result. It’s an object without any access token aud: string[]; azp: number; iat: number; iss: string; jti: string; org_code: string; permissions: KindePermissions; scp: string[]; sub: string; This is the object that I get and I need the string
Oli - Kinde
Oli - Kinde7mo ago
Hey @Sebastian Simionescu, Are you able to try the following code instead?
const { getAccessToken } = getKindeServerSession();
const accessToken = await getAccessToken();
const { getAccessToken } = getKindeServerSession();
const accessToken = await getAccessToken();
Sebastian Simionescu
This is code that I’m using @Oli - Kinde
Oli - Kinde
Oli - Kinde7mo ago
Okay noted, I was suggesting you to use the await term. I will have to get my nextJS expert teammate on this one. He will look into this 1st thing tomorrow morning.
Sebastian Simionescu
Thanks a lot. I’ll wait for it
Oli - Kinde
Oli - Kinde7mo ago
No worries, I'm sure we will be able to solve this issue. Hi @Sebastian Simionescu, The details you are receiving above is the payload of the access token. So do you mind elaborating on what exactly you are after?
I get any other thing beside a string with the token
Are you able to elaborate on this? If I understand you correctly, you want the access token string in it’s raw form. If so, you can get it with the following code:
import { cookies } from "next/headers";
const accessToken = cookies().get("access_token")?.value;
import { cookies } from "next/headers";
const accessToken = cookies().get("access_token")?.value;
Please let me know if you have any questions.