![GitHub Repo Cover](https://private-user-images.githubusercontent.com/18458907/291711345-aa4f9df6-980b-4b24-bb2f-d71c0f480971.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ1MzU5ODcsIm5iZiI6MTcyNDUzNTY4NywicGF0aCI6Ii8xODQ1ODkwNy8yOTE3MTEzNDUtYWE0ZjlkZjYtOTgwYi00YjI0LWJiMmYtZDcxYzBmNDgwOTcxLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI0VDIxNDEyN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQ0NDgzMGVmMzVmNjRkNGI3ZWM2ODU3MmRlMDJlOTI2NTNkYTlhNDRlODUzYTQ4MDgyMGU3Y2QyZDIyZjI3OWMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.FRU43jzndMO8tKFDkhKAPbx8L1wTd2RnBRzft7IRrNU)
The Corbado Node SDK provides convenient access to the Corbado Backend API from applications written in Node.js.
π Getting started | π οΈ Installation | π Advanced | π¬ Support & Feedback
- Node.js 8 or higher.
Use the following command to install the Corbado Node.js SDK:
npm install @corbado/node-sdk
To create a Node.js SDK instance you need to provide your Project ID
and API secret
which can be found at the Developer Panel.
const Corbado = require('@corbado/node-sdk');
const projectID = process.env.CORBADO_PROJECT_ID;
const apiSecret = process.env.CORBADO_API_SECRET;
const config = new Corbado.Config(projectID, apiSecret);
const sdk = new Corbado.SDK(config);
import {SDK, Config} from '@corbado/node-sdk';
const projectID = process.env.CORBADO_PROJECT_ID;
const apiSecret = process.env.CORBADO_API_SECRET;
const config = new Config(projectID, apiSecret);
const sdk = new SDK(config);
A list of examples can be found in the integration tests here.
The Corbado Node.js SDK provides the following services:
authTokens
for managing authentication tokens needed for own session management (examples)emailMagicLinks
for managing email magic links (examples)emailOTPs
for managing email OTPs (examples)sessions
for managing sessionssmsOTPs
for managing SMS OTPs (examples)users
for managing users (examples)validations
for validating email addresses and phone numbers (examples)
To use a specific service, such as sessions
, invoke it as shown below:
corbado.sessions().getCurrentUser(req);
The Corbado Node.js SDK throws exceptions for all errors. The following errors are thrown:
BaseError
for failed assertions and configuration errors (client side)ServerError
for server errors (server side)
If the Backend API returns a HTTP status code other than 200, the Corbado Node.js SDK throws a ServerError
. The ServerError
class provides convenient methods to access all important data:
try {
// Try to get non-existing user with ID 'usr-123456789'
const user = sdk.users().get('usr-123456789');
} catch (error: ServerError) {
// Show HTTP status code (404 in this case)
console.log(error.getHttpStatusCode());
// Show request ID (can be used in developer panel to look up the full request
// and response, see https://app.corbado.com/app/logs/requests)
console.log(error.getRequestID());
// Show full request data
console.log(error.getRequestData());
// Show runtime of request in seconds (server side)
console.log(error.getRuntime());
// Show validation error messages (server side validation in case of HTTP
// status code 400 (Bad Request))
console.log(error.getValidationMessages());
// Show full error data
console.log(error.getError());
}
If you encounter any bugs or have suggestions, please open an issue.
Join our Slack channel to discuss questions or ideas with the Corbado team and other developers.
You can also reach out to us via email at [email protected].
Please report suspected security vulnerabilities in private to [email protected]. Please do NOT create publicly viewable issues for suspected security vulnerabilities.