actions/createWeb2Session
Actions
CreateWeb2SessionFn()
CreateWeb2SessionFn: (
params
) =>Promise
\<AuthSession
>
Create a new web2 session
Parameters
• params: Web2CreateSessionParams
The parameters to create the session with
Returns
Promise
\<AuthSession
>
A promise that resolves when the session is created
Example
Basic usage:
import { createSdk } from "@compilot/js-sdk";
const compilotSdk = createSdk({ apiKey });
const sessionContent = await compilotSdk.createSession({
workflowId: "4f7b537f-0ae0-429c-98c8-3f6555ef23d6",
externalCustomerId: "123",
additionalInformation: {
email: "test@test.com",
phone: "+1234567890",
wallet: {
address: "tz1abc",
namespace: "tezos",
},
}
});
More often used as part of an api to protect the api key. Please find below an example of how to use the createSession function in Next.js:
import { createSdk } from "@compilot/js-sdk";
const compilotSdk = createSdk({ apiKey });
export default async function handler(req: NextApiRequest, res: NextApiResponse ) {
if (req.method !== "POST") {
res.setHeader("Allow", ["POST"]);
res.status(405).end(`Method ${req.method} Not Allowed`);
return;
}
const sessionRes = await compilotSdk.createSession({
workflowId: "4f7b537f-0ae0-429c-98c8-3f6555ef23d6",
externalCustomerId: req.session.externalCustomerId,
});
// Return the session to the client
res.status(200).json(sessionRes);
}