Val
12/08/2022, 8:27 AMrp_st
12/08/2022, 8:46 AMVal
12/08/2022, 8:47 AMrp_st
12/08/2022, 8:48 AMVal
12/08/2022, 9:08 AMrp_st
12/08/2022, 9:11 AMVal
12/08/2022, 9:25 AMrp_st
12/08/2022, 9:26 AMVal
12/09/2022, 2:06 PMCreateNewSession
and accessTokenPayload
?rp_st
12/09/2022, 2:40 PMVal
12/09/2022, 9:30 PMfunc main() {
supertokens.Init(supertokens.TypeInput{
RecipeList: []supertokens.Recipe{
session.Init(&sessmodels.TypeInput{
Override: &sessmodels.OverrideStruct{
Functions: func(originalImplementation sessmodels.RecipeInterface) sessmodels.RecipeInterface {
// First we copy the original implementation func
originalCreateNewSession := *originalImplementation.CreateNewSession
// Now we override the CreateNewSession function
(*originalImplementation.CreateNewSession) = func(res http.ResponseWriter, userID string, accessTokenPayload, sessionData map[string]interface{}, userContext supertokens.UserContext) (sessmodels.SessionContainer, error) {
// This goes in the access token, and is availble to read on the frontend.
if accessTokenPayload == nil {
accessTokenPayload = map[string]interface{}{}
}
accessTokenPayload["someKey"] = "someValue"
return originalCreateNewSession(res, userID, accessTokenPayload, sessionData, userContext)
}
return originalImplementation
},
},
}),
},
})
}
Like pass the metadata used when the user was createVal
12/09/2022, 9:30 PMVal
12/09/2022, 9:38 PMgolang
Functions: func(originalImplementation epmodels.RecipeInterface) epmodels.RecipeInterface {
originalSignIn := *originalImplementation.SignIn
*originalImplementation.SignIn = func(email, password string, userContext supertokens.UserContext) (epmodels.SignInResponse, error) {
// get user metadata and add it to the session
/*_, err := session.CreateNewSession(w, userId, map[string]interface{}{
"role": "role",
"ghost_id": ghostID,
}, nil)*/
return originalSignIn(email, password, userContext)
}
return originalImplementation
},
Val
12/09/2022, 9:40 PMVal
12/09/2022, 9:44 PMVal
12/09/2022, 10:00 PMgolang
Functions: func(originalImplementation sessmodels.RecipeInterface) sessmodels.RecipeInterface {
originalCreateNewSession := *originalImplementation.CreateNewSession
*originalImplementation.CreateNewSession = func(res http.ResponseWriter, userID string, accessTokenPayload, sessionData map[string]interface{}, userContext supertokens.UserContext) (sessmodels.SessionContainer, error) {
metadata, err := usermetadata.GetUserMetadata(userID)
if err != nil {
return nil, err
}
if accessTokenPayload == nil {
accessTokenPayload = map[string]interface{}{}
}
if accessTokenPayload["ext_id"] == nil {
accessTokenPayload["ext_id"] = metadata["ext_id"]
}
if accessTokenPayload["role"] == nil {
accessTokenPayload["role"] = metadata["role"]
}
return originalCreateNewSession(res, userID, accessTokenPayload, sessionData, userContext)
}
return originalImplementation
},
If you have a better approche I'm in but it's working 🙂rp_st
12/10/2022, 5:27 AMSuperTokens is an open source authentication solution offering features like: Different types of login: Email / password, Passwordless (OTP or Magic link based).
Powered by