Back-end Script
See the doc for more details about Authentication flow.
On your server, you should create an end point which will get the user email as request from your front end side, and which will query an AUTH TOKEN from the Mindset server. This AUTH TOKEN will be injected in the FE script.
Below an example of an EXPRESS API script
import express from "express";
const MINDSET-API-HOST = `TO-BE-PROVIDED-by-MINDSET`;
const mindset_api_key = 'YOUR-MINDSET-API-KEY'
const app = express();
app.get("/api/getusertoken/:useremail", async (req, res) => {
var user = req.params.useremail;
try {
const embedUserToken: any = await axios.post(
`https://${MINDSET-API-HOST}/api-authenticate-embedded-user`,
{
userEmail: req.params.useremail,
},
{
headers: {
'Content-Type': 'application/json',
'x-api-key': mindset_api_key
},
}
)
res.send(embedUserToken.data);
} catch (error: any) {
console.error(error);
console.error("Error", error, error.response.status, error.response, error);
res.status(500).send("Error getting token");
};
});
export default app;
Parameters required for your configuration
MINDSET-API-HOST
This URL is provided by the Mindset team.
YOUR-MINDSET-API-KEY
This API KEY can be generated in your Mindset App Admin portal.