https://supertokens.com/ logo
Title
u

_Nico

11/12/2022, 10:31 PM
Is this behaviour something expected? With this override:
session.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 though
r

rp

11/13/2022, 4:36 AM
Hey! What’s the response that you are getting?
I mean the contents of the response body
u

_Nico

11/13/2022, 5:01 AM
It's testing but as a plain text not json
r

rp

11/13/2022, 6:17 AM
Hmm. Perhaps @sattvikc can help tomorrow
s

sattvikc

11/14/2022, 5:24 AM
@_Nico that behaviour seems about right. what are you trying to achieve? can help with that.
session.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()