rp_st
12/03/2021, 2:36 PMgo
package main
import (
"fmt"
"net/http"
"github.com/go-chi/chi/v5"
"github.com/go-chi/cors"
"github.com/supertokens/supertokens-golang/recipe/emailpassword"
"github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels"
"github.com/supertokens/supertokens-golang/recipe/session"
"github.com/supertokens/supertokens-golang/supertokens"
)
func main() {
err := supertokens.Init(supertokens.TypeInput{
Supertokens: &supertokens.ConnectionInfo{
ConnectionURI: "https://try.supertokens.io",
},
AppInfo: supertokens.AppInfo{
AppName: "SuperTokens Demo App",
APIDomain: "http://localhost:3001",
WebsiteDomain: "http://localhost:3000",
},
RecipeList: []supertokens.Recipe{
emailpassword.Init(&epmodels.TypeInput{
ResetPasswordUsingTokenFeature: &epmodels.TypeInputResetPasswordUsingTokenFeature{CreateAndSendCustomEmail: func(user epmodels.User, passwordResetURLWithToken string) {
fmt.Println(passwordResetURLWithToken)
}},
}),
session.Init(nil),
},
})
if err != nil {
panic(err.Error())
}
r := chi.NewRouter()
r.Use(cors.Handler(cors.Options{
AllowedOrigins: []string{"http://localhost:3000"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowedHeaders: append([]string{"Content-Type"}, supertokens.GetAllCORSHeaders()...),
AllowCredentials: true,
}))
r.Use(supertokens.Middleware)
http.ListenAndServe(":3001", r)
}