Thanks for your reply!
Hmm seems like my initial post wasn’t clear enough so let me explain a bit further:
-
Mobile app: using client OSDK ( so not a service user, a public client)
-
TS repo on foundry: typescript functions, exposed to clients through OSDK.
Here’s a fictional scenario + pseudo code to explain the situation:
I want to expose a function that executes a certain logic depending on the current user, for example creating a customer in an external system.
So we’re gonna have a function like this:
async createCustomerInExternalSystem() {
const theInfoIwant = await fetch("externalSystemUrl/customers", { method: "POST" })
return theInfoIwant
}
Now image the externalSystemUrl/customers
endpoint requires a certain information from the user, for example his email. I’d then like to do something like this:
async createCustomerInExternalSystem() {
const currentUser = getCurrentUser() // gotten from the token that's in the http call for this method
const theInfoIwant = await fetch("externalSystemUrl/customers", {
method: "POST";
body: {
email: currentUser.email
}
})
return theInfoIwant
}
or even using injection if possible as a few backend frameworks do, something like this:
// gotten from the token that's in the http call for this method
async createCustomerInExternalSystem(currentUser?: Principal) {
const theInfoIwant = await fetch("externalSystemUrl/customers", {
method: "POST";
body: {
email: currentUser.email
}
})
return theInfoIwant
}
Then, the mobile app would call this function using the public OSDK client:
client(createMeasurementV2).applyAction()
and the TS function would get the current user based on the authenticated user from the app, as he sends a Foundry token in the request.
I hope it’s a bit clearer now.
I currently can’t really inject the current user into a function.
Is that currently possible ?
Thanks !