Hey Im overriding the sign in/up api specifically ...
# support-questions-legacy
d
Hey Im overriding the sign in/up api specifically the third party sign in up. I want to do something after a user sign in/up. My problem is that if the user is created successfully and that something fails then the api still returns the cookies and tokens to the client and i dont want it to do it, im fine with the user being created in supertokens but i still want the api to act like the sign in failed. code for example (im using golang)
Copy code
APIs: func(originalImplementation tpmodels.APIInterface) tpmodels.APIInterface {

    originalSignInUpPOST := *originalImplementation.SignInUpPOST
    
    (*originalImplementation.SignInUpPOST) = func(provider tpmodels.TypeProvider, code string, authCodeResponse interface{}, redirectURI string, options tpmodels.APIOptions, userContext supertokens.UserContext) (tpmodels.SignInUpPOSTResponse, error) {
        
        response, err := originalSignInUpPOST(provider, code, authCodeResponse, redirectURI, options, userContext)
        
        if err != nil {
            return tpmodels.SignInUpPOSTResponse{}, err
        }

        if response.OK != nil {
            user := response.OK.User
            somethingError := doSomething(user)

            if somethingError != nil {
                return tpmodels.SignInUpPOSTResponse{}, somethingError
            }

        }
        return response, nil
    }

    return originalImplementation
},
If doSomething(user) fails Im getting the error i expect and also a bad http code from the signinup api but its still come with the Set-Cookie and the FrontToken headers in the response and i do not want that. Any idea how can i prevent that?
r
Hey!
the cookies are attached to the response write in the
options
argument to the function. You can perhaps remove all the headers from there? You can also open an issue about this on our github and we can come up with an inbuilt solution for this as it seems like the right thing to do.
d
Hey, I see that makes sense why didnt i think about that. I actually went with checking in OnSuperTokensAPIError if the error i have is the specific error i returned in the SignInUpPOST and if it is i removed the headers from the response. but i guess i can do it directly in the API seems better. Thanks for the help.
r
cool!