hi!
what you need to do is to get the sessionToken in the frontend and then pass that to your backend (typically in an http header) when you do requests. here is an example code snippet:
import mondaySdk from 'monday-sdk-js';
const monday = mondaySdk();
async function getSessionToken() {
return (await monday.get('sessionToken')).data;
}
async function getFoo() {
const sessionToken = await getSessionToken();
const response = await fetch(`https://YOUR-BACKEND.COM/api/foo`, {
method: 'GET',
headers: {
Authorization: `Bearer ${sessionToken}`,
},
});
return await response.json();
}
your backend then needs to extract the sessionToken from the http headers and verify it. the extracted sessionToken also contains the userId. here is an example:
const jwt = require('jsonwebtoken');
const { userId } = jwt.verify(
getSessionTokenFromHeaders(), // you need to implement this function
process.env.MONDAY_SIGNING_SECRET
);
console.log('current user id', userId);
hope that helps.
simon
Hi, thanks for your reply.
In my case, I’m not trying to get the user on a client, but on the board itself (I’m not sure if this is what you were thinking when you said frontend).
The session token gives the user that originally installed the app, not the user who is currently logged in. I heard that the trigger (using the user output) would give this logged in user (the user that actually triggered the change), but when I try, even that is returning the user that installed the app instead of the user that made the change/logged-in user.
@basdebruin (Current logged In user) had a post where he said that the token behavior was to be expected, as it was responding with the info from the app installation. But it’s the trigger response of that user instead of the user triggering the change that has me puzzled.
Moshe
hey @Msh,
i just double-checked this: i logged in as a test user and opened up a board view (provided by a test app) and the userId stored in the sessionToken was the one of the test-user. i then switched back to my main user and opened the board view there and the sessionToken contained the userId of that user. so i was not able to reproduce the behavior you are describing.
in the thread you linked, it’s not clear if they are actually talking about the sessionToken or another token.
simon