Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
The Stytch Node library makes it easy to use the Stytch user infrastructure API in server-side JavaScript applications.
It pairs well with the Stytch Web SDK or your own custom authentication flow.
This library is tested with all current LTS versions of Node - 16, 18, and 20.
npm install stytch
# or
yarn add stytch
You can find your API credentials in the Stytch Dashboard.
This client library supports all of Stytch's live products:
B2C
B2B
Create an API client:
const stytch = require("stytch");
// Or as an ES6 module:
// import * as stytch from "stytch";
const client = new stytch.Client({
project_id: "project-live-c60c0abe-c25a-4472-a9ed-320c6667d317",
secret: "secret-live-80JASucyk7z_G8Z-7dVwZVGXL5NT_qGAQ2I=",
env: stytch.envs.test,
});
Send a magic link by email:
client.magicLinks.email
.loginOrCreate({
email: "sandbox@stytch.com",
login_magic_link_url: "https://example.com/authenticate",
signup_magic_link_url: "https://example.com/authenticate",
})
.then((res) => console.log(res))
.catch((err) => console.error(err));
Authenticate the token from the magic link:
client.magicLinks
.authenticate("DOYoip3rvIMMW5lgItikFK-Ak1CfMsgjuiCyI7uuU94=")
.then((res) => console.log(res))
.catch((err) => console.error(err));
Create an API client:
const stytch = require("stytch");
// Or as an ES6 module:
// import * as stytch from "stytch";
const client = new stytch.B2BClient({
project_id: "project-live-c60c0abe-c25a-4472-a9ed-320c6667d317",
secret: "secret-live-80JASucyk7z_G8Z-7dVwZVGXL5NT_qGAQ2I=",
env: stytch.envs.test,
});
Create an organization
client.organizations
.create({
organization_name: "Acme Co",
organization_slug: "acme-co",
email_allowed_domains: ["acme.co"],
})
.then((res) => console.log(res))
.catch((err) => console.error(err));
Log the first user into the organization
client.magicLinks.loginOrSignup({
organization_id: "organization-id-from-create-response-..."
email_address: "admin@acme.co"
})
.then((res) => console.log(res))
.catch((err) => console.error(err));
This package includes TypeScript declarations for the Stytch API.
Request and response types will always follow the format $Vertical$Product$Method(Request|Response)
-
for example the B2BMagicLinksAuthenticateRequest
maps to the B2B
Authenticate Magic Link endpoint, while the
B2CMagicLinksAuthenticateRequest
maps to the B2C Authenticate Magic Link endpoint.
Stytch errors always include an error_type
field you can use to identify them:
client.magicLinks
.authenticate("not-a-token!")
.then((res) => console.log(res))
.catch((err) => {
if (err.error_type === "invalid_token") {
console.log("Whoops! Try again?");
}
});
Learn more about errors in the docs.
The Stytch client can be customized to use your own HTTPS agent. For example, you can enable HTTPS Keep-Alive to avoid the cost of establishing a new connection with the Stytch servers on every request.
const agent = new https.Agent({
keepAlive: true,
});
const client = new stytch.Client({
project_id: "project-live-c60c0abe-c25a-4472-a9ed-320c6667d317",
secret: "secret-live-80JASucyk7z_G8Z-7dVwZVGXL5NT_qGAQ2I=",
env: stytch.envs.test,
agent,
});
See example requests and responses for all the endpoints in the Stytch API Reference.
Follow one of the integration guides or start with one of our example apps.
If you've found a bug, open an issue!
If you have questions or want help troubleshooting, join us in Slack or email support@stytch.com.
If you've found a security vulnerability, please follow our responsible disclosure instructions.
See DEVELOPMENT.md
Everyone interacting in the Stytch project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
FAQs
A wrapper for the Stytch API
We found that stytch demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.