I'm getting a token with claims from an authentication provider. It's a JSON object that looks like this:
{
"email": "user@example.org",
"urn:dev:claims/user-id": "123"
}
I'm trying to create a representative interface or type on my client to access this token keys correctly. The problem is the "dev" part of "urn:dev:claims/user-id" above is dynamic, it comes from environment variable as such:
const claimKey = urn:${process.env.REACT_APP_ENV}:claims/user-id
When I try the following:
interface MyInterface {
email: string;
[claimKey]: string;
}
It does not work.
Here's a full reproducible example:
const env = {
REACT_APP_ENV: "dynamic-value"
}
const token = {
"email": "user@example.org",
"urn:dev:claims/user-id": "123"
}
const claimKey = `urn:${env.REACT_APP_ENV}:claims/user-id`
interface MyInterface {
email: string;
[claimKey]: string;
}