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 "github.com/supertokens/supertokens-go/supertokens"
http.HandleFunc("/refresh", supertokens.Middleware(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("success"))
}))
import "github.com/supertokens/supertokens-go/gin/supertokens"
r.POST("/refresh", supertokens.Middleware(), func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"msg" : "success",
})
}))
2) Add error handlers
- By default, SuperTokens takes care of handling session errors for you. However, you can define your own logic as well.
config.yaml
3) Change SuperTokens - Set appropriate values for
cookie_domain
andrefresh_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
http://localhost:3567
. If using the trial instance, usehttps://try.supertokens.com
import "github.com/supertokens/supertokens-go/supertokens"
func main() {
// ; separated addresses
supertokens.Config(supertokens.ConfigMap{
Hosts: "http://localhost:9000;https://try.supertokens.com",
})
}
import "github.com/supertokens/supertokens-go/gin/supertokens"
func main() {
// ; separated addresses
supertokens.Config(supertokens.ConfigMap{
Hosts: "http://localhost:9000;https://try.supertokens.com",
})
}
- All config values (these will override the ones specified in the
config.yaml
file):Hosts: string
-;
separated string for all the locations of SuperTokens instances.AccessTokenPath: string
- Seeaccess_token_path
in the config.yaml fileRefreshAPIPath: string
- Seerefresh_api_path
in the config.yaml fileCookieDomain: string
- Seecookie_domain
in the config.yaml fileCookieSecure: *bool
- Seecookie_secure
in the config.yaml fileCookieSameSite: string
- Seecookie_same_site
in the config.yaml file