Skip to content

Commit

Permalink
Merge pull request #699 from supertokens/golang-snippet-fix
Browse files Browse the repository at this point in the history
fix: empty session snippet for golang
  • Loading branch information
rishabhpoddar authored Aug 23, 2023
2 parents 8ade699 + 6d89d4e commit 6ae52f7
Show file tree
Hide file tree
Showing 7 changed files with 313 additions and 27 deletions.
44 changes: 43 additions & 1 deletion v2/emailpassword/advanced-customizations/user-context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ import (
"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/recipe/session/claims"
"github.com/supertokens/supertokens-golang/recipe/session/sessmodels"
"github.com/supertokens/supertokens-golang/supertokens"
)
Expand All @@ -262,7 +263,48 @@ func main() {
* only then will the (*userContext)["isSignUp"] === true
* (see above code).
*/
return nil, nil // this is an empty session. It won't result in a session being created for the user.
return &sessmodels.TypeSessionContainer{
RevokeSession: func() error { return nil },
GetSessionDataInDatabase: func() (map[string]interface{}, error) { return nil, nil },
UpdateSessionDataInDatabase: func(newSessionData map[string]interface{}) error { return nil },
GetUserID: func() string { return "" },
GetTenantId: func() string { return "public" },
GetAccessTokenPayload: func() map[string]interface{} { return nil },
GetHandle: func() string { return "" },
GetAllSessionTokensDangerously: func() sessmodels.SessionTokens { return sessmodels.SessionTokens{} },
GetAccessToken: func() string { return "" },
GetTimeCreated: func() (uint64, error) { return 0, nil },
GetExpiry: func() (uint64, error) { return 0, nil },
RevokeSessionWithContext: func(userContext supertokens.UserContext) error { return nil },
GetSessionDataInDatabaseWithContext: func(userContext supertokens.UserContext) (map[string]interface{}, error) { return nil, nil },
UpdateSessionDataInDatabaseWithContext: func(newSessionData map[string]interface{}, userContext supertokens.UserContext) error { return nil },
GetUserIDWithContext: func(userContext supertokens.UserContext) string { return "" },
GetTenantIdWithContext: func(userContext supertokens.UserContext) string { return "public" },
GetAccessTokenPayloadWithContext: func(userContext supertokens.UserContext) map[string]interface{} { return nil },
GetHandleWithContext: func(userContext supertokens.UserContext) string { return "" },
GetAccessTokenWithContext: func(userContext supertokens.UserContext) string { return "" },
GetTimeCreatedWithContext: func(userContext supertokens.UserContext) (uint64, error) { return 0, nil },
GetExpiryWithContext: func(userContext supertokens.UserContext) (uint64, error) { return 0, nil },
MergeIntoAccessTokenPayloadWithContext: func(accessTokenPayloadUpdate map[string]interface{}, userContext supertokens.UserContext) error {
return nil
},
AssertClaimsWithContext: func(claimValidators []claims.SessionClaimValidator, userContext supertokens.UserContext) error {
return nil
},
FetchAndSetClaimWithContext: func(claim *claims.TypeSessionClaim, userContext supertokens.UserContext) error { return nil },
SetClaimValueWithContext: func(claim *claims.TypeSessionClaim, value interface{}, userContext supertokens.UserContext) error {
return nil
},
GetClaimValueWithContext: func(claim *claims.TypeSessionClaim, userContext supertokens.UserContext) interface{} { return nil },
RemoveClaimWithContext: func(claim *claims.TypeSessionClaim, userContext supertokens.UserContext) error { return nil },
MergeIntoAccessTokenPayload: func(accessTokenPayloadUpdate map[string]interface{}) error { return nil },
AssertClaims: func(claimValidators []claims.SessionClaimValidator) error { return nil },
FetchAndSetClaim: func(claim *claims.TypeSessionClaim) error { return nil },
SetClaimValue: func(claim *claims.TypeSessionClaim, value interface{}) error { return nil },
GetClaimValue: func(claim *claims.TypeSessionClaim) interface{} { return nil },
RemoveClaim: func(claim *claims.TypeSessionClaim) error { return nil },
AttachToRequestResponse: func(info sessmodels.RequestResponseInfo) error { return nil },
}, nil // this is an empty session. It won't result in a session being created for the user.
}

return ogCreateNewSession(userID, accessTokenPayload, sessionDataInDatabase, disableAntiCsrf, tenantId, userContext)
Expand Down
44 changes: 43 additions & 1 deletion v2/passwordless/advanced-customizations/user-context.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ import (
"github.com/supertokens/supertokens-golang/recipe/passwordless"
"github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels"
"github.com/supertokens/supertokens-golang/recipe/session"
"github.com/supertokens/supertokens-golang/recipe/session/claims"
"github.com/supertokens/supertokens-golang/recipe/session/sessmodels"
"github.com/supertokens/supertokens-golang/supertokens"
)
Expand All @@ -310,7 +311,48 @@ func main() {
* only then will the (*userContext)["isSignUp"] === true
* (see above code).
*/
return nil, nil // this is an empty session. It won't result in a session being created for the user.
return &sessmodels.TypeSessionContainer{
RevokeSession: func() error { return nil },
GetSessionDataInDatabase: func() (map[string]interface{}, error) { return nil, nil },
UpdateSessionDataInDatabase: func(newSessionData map[string]interface{}) error { return nil },
GetUserID: func() string { return "" },
GetTenantId: func() string { return "public" },
GetAccessTokenPayload: func() map[string]interface{} { return nil },
GetHandle: func() string { return "" },
GetAllSessionTokensDangerously: func() sessmodels.SessionTokens { return sessmodels.SessionTokens{} },
GetAccessToken: func() string { return "" },
GetTimeCreated: func() (uint64, error) { return 0, nil },
GetExpiry: func() (uint64, error) { return 0, nil },
RevokeSessionWithContext: func(userContext supertokens.UserContext) error { return nil },
GetSessionDataInDatabaseWithContext: func(userContext supertokens.UserContext) (map[string]interface{}, error) { return nil, nil },
UpdateSessionDataInDatabaseWithContext: func(newSessionData map[string]interface{}, userContext supertokens.UserContext) error { return nil },
GetUserIDWithContext: func(userContext supertokens.UserContext) string { return "" },
GetTenantIdWithContext: func(userContext supertokens.UserContext) string { return "public" },
GetAccessTokenPayloadWithContext: func(userContext supertokens.UserContext) map[string]interface{} { return nil },
GetHandleWithContext: func(userContext supertokens.UserContext) string { return "" },
GetAccessTokenWithContext: func(userContext supertokens.UserContext) string { return "" },
GetTimeCreatedWithContext: func(userContext supertokens.UserContext) (uint64, error) { return 0, nil },
GetExpiryWithContext: func(userContext supertokens.UserContext) (uint64, error) { return 0, nil },
MergeIntoAccessTokenPayloadWithContext: func(accessTokenPayloadUpdate map[string]interface{}, userContext supertokens.UserContext) error {
return nil
},
AssertClaimsWithContext: func(claimValidators []claims.SessionClaimValidator, userContext supertokens.UserContext) error {
return nil
},
FetchAndSetClaimWithContext: func(claim *claims.TypeSessionClaim, userContext supertokens.UserContext) error { return nil },
SetClaimValueWithContext: func(claim *claims.TypeSessionClaim, value interface{}, userContext supertokens.UserContext) error {
return nil
},
GetClaimValueWithContext: func(claim *claims.TypeSessionClaim, userContext supertokens.UserContext) interface{} { return nil },
RemoveClaimWithContext: func(claim *claims.TypeSessionClaim, userContext supertokens.UserContext) error { return nil },
MergeIntoAccessTokenPayload: func(accessTokenPayloadUpdate map[string]interface{}) error { return nil },
AssertClaims: func(claimValidators []claims.SessionClaimValidator) error { return nil },
FetchAndSetClaim: func(claim *claims.TypeSessionClaim) error { return nil },
SetClaimValue: func(claim *claims.TypeSessionClaim, value interface{}) error { return nil },
GetClaimValue: func(claim *claims.TypeSessionClaim) interface{} { return nil },
RemoveClaim: func(claim *claims.TypeSessionClaim) error { return nil },
AttachToRequestResponse: func(info sessmodels.RequestResponseInfo) error { return nil },
}, nil // this is an empty session. It won't result in a session being created for the user.
}

return ogCreateNewSession(userID, accessTokenPayload, sessionDataInDatabase, disableAntiCsrf, tenantId, userContext)
Expand Down
51 changes: 29 additions & 22 deletions v2/src/plugins/codeTypeChecking/goEnv/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,52 @@ go 1.17

require (
github.com/gin-contrib/cors v1.4.0
github.com/gin-gonic/gin v1.8.2
github.com/gin-gonic/gin v1.9.1
github.com/go-chi/chi v1.5.4
github.com/go-chi/cors v1.2.1
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/supertokens/supertokens-golang v0.12.11-0.20230814151216-eb760d701836
github.com/supertokens/supertokens-golang v0.13.0
)

require (
github.com/MicahParks/keyfunc v1.9.0 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/derekstavis/go-qs v0.0.0-20180720192143-9eef69e6c4e7 // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.11.1 // indirect
github.com/goccy/go-json v0.9.11 // indirect
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.15.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nyaruka/phonenumbers v1.0.73 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/nyaruka/phonenumbers v1.1.8 // indirect
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.8.1 // indirect
github.com/twilio/twilio-go v0.26.0 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
golang.org/x/crypto v0.2.0 // indirect
golang.org/x/net v0.4.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/twilio/twilio-go v1.11.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
gopkg.in/h2non/gock.v1 v1.1.2 // indirect
Expand Down
Loading

0 comments on commit 6ae52f7

Please sign in to comment.