SuperTokens

No results

Help CenterGetting StartedInstalling SuperTokens: A Step-by-Step Guide

Installing SuperTokens: A Step-by-Step Guide

Last updated March 1, 2024

Introduction

Welcome to the world of secure and easy-to-implement authentication solutions with SuperTokens! Whether you're building a new application or looking to enhance an existing one with robust authentication features, SuperTokens offers a flexible, open-source solution that can be tailored to meet your needs. This guide will walk you through the installation process of SuperTokens, ensuring you have a smooth start. Let's dive in!

Prerequisites

Before we begin, ensure you have the following:

  • Node.js installed on your system (version 12.x or later).
  • A basic understanding of your project's backend framework (e.g., Express.js for Node.js applications).
  • Access to a terminal or command prompt.

Step-by-Step Installation

  1. Install the SuperTokens Core bashCopy code docker pull supertokens/supertokens-<your-preferred-database>
  • The SuperTokens Core is the heart of the authentication system. Start by downloading and running the SuperTokens Core on your server. You can use Docker or directly download binaries available for your operating system from the SuperTokens website.
  1. Install the SuperTokens SDK bashCopy code npm install supertokens-node or bashCopy code yarn add supertokens-node
  • Choose the SDK that matches your application's backend language. For a Node.js application, you can install the SuperTokens Node.js SDK using npm or yarn.
  1. Configure SuperTokens javascriptCopy code const supertokens = require("supertokens-node"); const { middleware } = require("supertokens-node/framework/express"); const express = require("express"); const app = express(); supertokens.init({ framework: "express", supertokens: { connectionURI: "http://localhost:3567", }, appInfo: { appName: "Your App Name", apiDomain: "http://localhost:3000", websiteDomain: "http://localhost:3000", }, recipeList: [ // List of SuperTokens features you want to use ], }); app.use(middleware()); // Your app routes go here app.listen(3000, () =>console.log("Server is running on port 3000"));
  • After installing the SDK, you need to configure SuperTokens in your application. This involves setting up the connection to the SuperTokens Core and configuring your authentication APIs.
  1. Start the SuperTokens Core bashCopy code docker run -p 3567:3567 -d supertokens/supertokens-<your-preferred-database>
  • Before running your application, ensure the SuperTokens Core is running. If you're using Docker, you can start the Core with the following command:
  1. Run Your Application bashCopy code node app.js
  • With the SuperTokens Core running and your application configured to use SuperTokens, you're now ready to start your application server. Navigate to your project directory in the terminal and run your application.
  1. Verify Installation
  • Finally, verify that SuperTokens is correctly installed and running by making a test API call to your application's authentication endpoint, or by checking the SuperTokens dashboard if you have it set up.

Congratulations! You have successfully installed SuperTokens in your application. You're now ready to dive deeper into adding authentication routes, configuring sessions, and customizing authentication flows to suit your application's needs.

Conclusion

Installing SuperTokens is just the beginning. With its flexible architecture and comprehensive documentation, you're well-equipped to build secure and scalable authentication systems. Explore the SuperTokens documentation for detailed guides on implementing various authentication features and customizing your setup. Happy coding!

Was this article helpful?