_Nico
11/12/2022, 10:31 PMsession.Init(&sessmodels.TypeInput{
Override: &sessmodels.OverrideStruct{
APIs: func(originalImplementation sessmodels.APIInterface) sessmodels.APIInterface {
*originalImplementation.VerifySession = func(verifySessionOptions *sessmodels.VerifySessionOptions, options sessmodels.APIOptions, userContext supertokens.UserContext) (sessmodels.SessionContainer, error) {
options.Res.Header().Set("Content-Type", "application/json")
s, _ := session.GetSessionWithContext(options.Req, options.Res, verifySessionOptions, userContext)
if s == nil {
return nil, errors.New("testing")
}
return s, nil
}
return originalImplementation
},
},
}),
And this middleware:
func verifySession(options *sessmodels.VerifySessionOptions) gin.HandlerFunc {
return func(c *gin.Context) {
session.VerifySession(options, func(rw http.ResponseWriter, r *http.Request) {
c.Request = c.Request.WithContext(r.Context())
c.Next()
})(c.Writer, c.Request)
c.AbortWithStatus(401)
}
}
The response is plain text instead of a json in postman... I don't know why thoughrp_st
11/13/2022, 4:36 AMrp_st
11/13/2022, 4:36 AM_Nico
11/13/2022, 5:01 AMrp_st
11/13/2022, 6:17 AMsattvikc
11/14/2022, 5:24 AMsattvikc
11/14/2022, 6:37 AMsession.Init(&sessmodels.TypeInput{
Override: &sessmodels.OverrideStruct{
APIs: func(originalImplementation sessmodels.APIInterface) sessmodels.APIInterface {
*originalImplementation.VerifySession = func(verifySessionOptions *sessmodels.VerifySessionOptions, options sessmodels.APIOptions, userContext supertokens.UserContext) (sessmodels.SessionContainer, error) {
options.Res.Header().Set("Content-Type", "application/json")
s, err := session.GetSessionWithContext(options.Req, options.Res, verifySessionOptions, userContext)
if err != nil {
return nil, err
}
if s == nil {
return nil, errors.New("testing")
}
return s, nil
}
return originalImplementation
},
},
}),
You should be returning the error returned by the SDK, so that 401 response is also sent by the SDK. This is because, VerifySession already sends the response and thus, c.AbortWithStatus(401) has no effect. Otherwise, you can also use the options.Res object to write your own response, something like options.Res.WriteHeader(401), followed by options.Res.Write()SuperTokens is an open source authentication solution offering features like: Different types of login: Email / password, Passwordless (OTP or Magic link based).
Powered by