Is this behaviour something expected? With this override: `session.Init(&sessmodels.TypeInput{ O...
u
Is this behaviour something expected? With this override:
Copy code
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:
Copy code
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
Hey! What’s the response that you are getting?
I mean the contents of the response body
u
It's testing but as a plain text not json
r
Hmm. Perhaps @sattvikc can help tomorrow
s
@_Nico that behaviour seems about right. what are you trying to achieve? can help with that.
Copy code
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()