Vexor

Vexor.init()

Static Initialization

There are 3 ways to instantiate a Vexor instance:

  1. Using the new Vexor() constructor with publishable key, project id and secret key.
  2. Using the Vexor.init() static method.
  3. Using the Vexor.fromEnv() method to initialize the Vexor instance from environment variables.

The Vexor.init() method provides a convenient way to create a new Vexor instance without using the new keyword. It's particularly useful when you want to create an instance in a single line of code or when working with dependency injection systems. This method internally calls the Vexor constructor with the provided parameters, creating and returning a new Vexor instance.

StaticVexor.init(params)

Vexor.init()

Initialize a new Vexor instance using a static method.

Parameters

Returns

Returns a new Vexor instance.

import { Vexor } from 'vexor';
 
export const vexor = Vexor.init({
  publishableKey: 'your_publishable_key',
  projectId: 'your_project_id',
  secretKey: 'your_secret_key' // Optional
});

Recommendations

  1. Create a .env file in your project root and add your Vexor environment variables:
PUBLIC_VEXOR_KEY=pk_test_1234567890
PUBLIC_VEXOR_PROJECT=proj_0987654321
VEXOR_SECRET_KEY=sk_test_1234567890

WARNING: Do not store any secrets (such as VEXOR_SECRET_KEY) in your React app! These keys should be handled on the server side.

  1. Create a vexor.ts file in your lib or utils folder and export the Vexor instance:
import { Vexor } from 'vexor';
 
export const vexor = Vexor.init({
  publishableKey: process.env.PUBLIC_VEXOR_KEY,
  projectId: process.env.PUBLIC_VEXOR_PROJECT,
  secretKey: process.env.VEXOR_SECRET_KEY
});

Choose the method that best fits your application's architecture and security requirements.

The Vexor.init() method is functionally equivalent to using the new Vexor() constructor. It's provided as an alternative syntax that some developers may find more intuitive or easier to use in certain contexts.

On this page