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 config.yaml
- Set appropriate values for
cookie_domain
and refresh_api_path
in the SuperTokens config.yaml file. OR
- 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).
- The default location of SuperTokens is
localhost:3567
. If using the trial instance, use https://try.supertokens.com
import io.supertokens.javalin.*;
SuperTokens.config().withHosts("http://localhost:9000;https://try.supertokens.com");
- All config values (these will override the ones specified in the
config.yaml
file):
withHosts(string)
- ;
separated string for all the locations of SuperTokens instances.
withAccessTokenPath(string)
- See access_token_path
in the config.yaml file
withRefreshApiPath(string)
- See refresh_api_path
in the config.yaml file
withCookieDomain(string)
- See cookie_domain
in the config.yaml file
withCookieSecure(boolean)
- See cookie_secure
in the config.yaml file
withCookieSameSite(string)
- See cookie_same_site
in the config.yaml file