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.
4) (Optional) Specify the location of SuperTokens Service
- 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
import "github.com/supertokens/supertokens-go/supertokens"
func main() {
// ; separated addresses
supertokens.Config("localhost:9000;192.168.1.2:8080")
}
import "github.com/supertokens/supertokens-go/gin/supertokens"
func main() {
// ; separated addresses
supertokens.Config("localhost:9000;192.168.1.2:8080")
}