You are viewing an older version of the docs. This is only relevant if the core version you are using is <= v2.5. Please visit the more recent docs for newer versions of the core.
Minimum setup (2 mins)
1) Initialise SuperTokens
let supertokens = require("supertokens-node");
let app = express();
app.use(supertokens.init({
hosts: "http://localhost:3567;https://try.supertokens.com",
apiKey: "key"
}));
import * as supertokens from "supertokens-node";
let app = express();
app.use(supertokens.init({
hosts: "http://localhost:3567;https://try.supertokens.com",
apiKey: "key"
}));
- All config values:
hosts: string
-;
separated string for all the locations of SuperTokens instances.accessTokenPath: string
- Seeaccess_token_path
in the config.yaml filerefreshTokenPath: string
- Seerefresh_api_path
in the config.yaml filecookieDomain: string
- Seecookie_domain
in the config.yaml filecookieSecure: boolean
- Seecookie_secure
in the config.yaml filecookieSameSite: string
- Seecookie_same_site
in the config.yaml fileapiKey
- Specify any one of the API keys that you have set in the config.yaml
- There are more config values in the
config.yaml
file (for on premise) or on the SaaS dashboard. The values you set via theinit
function above will override those. - The
init
function returns a middleware that automatically manages refreshing of a session.
2) Add an error handler
- Add this at the end of all your routes, but before your error middleware.
- By default, SuperTokens takes care of handling session errors for you. However, you can define your own logic as well.
let supertokens = require("supertokens-node");
let app = express();
// add all your routes here...
// add SuperTokens error middleware
app.use(supertokens.errorHandler());
// add your error middleware
app.use((err, req, res, next) => {
res.status(500).send(err);
})
import * as supertokens from "supertokens-node";
let app = express();
// add all your routes here...
// add SuperTokens error middleware
app.use(supertokens.errorHandler());
// add your error middleware
app.use((err, req, res, next) => {
res.status(500).send(err);
})