Minimum setup (2 mins)
1) Create a refresh API
- This API will be used to get new access and refresh tokens (done automatically from our frontend SDK).
import io.supertokens.javalin.*;
app.before("/refresh", SuperTokens.middleware());
app.post("/refresh", ctx -> {
ctx.result("");
});
2) Add an error handler
- By default, SuperTokens takes care of handling session errors for you. However, you can define your own logic as well.
import io.supertokens.javalin.*;
app.exception(SuperTokensException.class, SuperTokens.exceptionHandler());
3) Change SuperTokens configurations
- If using our managed service, then you can change configuration values on your dashboard using the config.yaml file. button. Instead, if using the self hosted version, please make changes to the
- Set appropriate values for
cookie_domain
andrefresh_api_path
. - You can also specify these values via the
SuperTokens.config
function mentioned below
4) Specify the location of SuperTokens Service and other configs
- Call this somewhere close to where you initialise the app.
- You can provide multiple addresses in case you are running more than one SuperTokens service (as shown below).
- If using our managed service, you can get the connection information using the
localhost:3567
. If using the trial instance, usehttps://try.supertokens.com
.
button on your dashboard. For self hosted, the default location of SuperTokens is - You can also specify an API key if you have set one in the
config.yaml
file
import io.supertokens.javalin.*;
// ; separated addresses
SuperTokens.config().withHosts("http://localhost:9000;https://try.supertokens.com", "apiKey");
- All config values (these will override the ones specified in the
config.yaml
file):withHosts(String hosts, String apiKey)
-;
separated string for all the locations of SuperTokens instances. An optional apiKey argument.withAccessTokenPath(string)
- Seeaccess_token_path
in the config.yaml filewithRefreshApiPath(string)
- Seerefresh_api_path
in the config.yaml filewithCookieDomain(string)
- Seecookie_domain
in the config.yaml filewithCookieSecure(boolean)
- Seecookie_secure
in the config.yaml filewithCookieSameSite(string)
- Seecookie_same_site
in the config.yaml file