Skip to content

Commit

Permalink
fixes sessionrequest functions file
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Nov 23, 2023
1 parent 43e8f7c commit ace4b09
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions recipe/session/sessionRequestFunctions.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,18 @@ func CreateNewSessionInRequest(req *http.Request, res http.ResponseWriter, tenan
return nil, err
}
if token != nil {
ClearSession(config, res, tokenTransferMethod)
ClearSession(config, res, tokenTransferMethod, req, userContext)
}
}
}

supertokens.LogDebugMessage("createNewSession: Cleared old tokens")

sessionResponse.AttachToRequestResponse(sessmodels.RequestResponseInfo{
sessionResponse.AttachToRequestResponseWithContext(sessmodels.RequestResponseInfo{
Res: res,
Req: req,
TokenTransferMethod: outputTokenTransferMethod,
})
}, userContext)
supertokens.LogDebugMessage("createNewSession: Attached new tokens to res")

return sessionResponse, nil
Expand Down Expand Up @@ -288,11 +288,11 @@ func GetSessionFromRequest(req *http.Request, res http.ResponseWriter, config se
transferMethod = allowedTokenTransferMethod
}

err = (*sessionResult).AttachToRequestResponse(sessmodels.RequestResponseInfo{
err = (*sessionResult).AttachToRequestResponseWithContext(sessmodels.RequestResponseInfo{
Res: res,
Req: req,
TokenTransferMethod: transferMethod,
})
}, userContext)

if err != nil {
return nil, err
Expand Down Expand Up @@ -336,7 +336,7 @@ func RefreshSessionInRequest(req *http.Request, res http.ResponseWriter, config
} else {
if GetCookieValue(req, legacyIdRefreshTokenCookieName) != nil {
supertokens.LogDebugMessage("refreshSession: cleared legacy id refresh token because refresh token was not found")
setCookie(config, res, legacyIdRefreshTokenCookieName, "", 0, "accessTokenPath")
setCookie(config, res, legacyIdRefreshTokenCookieName, "", 0, "accessTokenPath", req, userContext)
}

supertokens.LogDebugMessage("refreshSession: UNAUTHORISED because refresh token in request is undefined")
Expand Down Expand Up @@ -384,7 +384,7 @@ func RefreshSessionInRequest(req *http.Request, res http.ResponseWriter, config
if (isTokenTheftDetectedErr) || (isUnauthorisedErr && unauthorisedErr.ClearTokens != nil && *unauthorisedErr.ClearTokens) {
if GetCookieValue(req, legacyIdRefreshTokenCookieName) != nil {
supertokens.LogDebugMessage("refreshSession: cleared legacy id refresh token because refresh is clearing other tokens")
setCookie(config, res, legacyIdRefreshTokenCookieName, "", 0, "accessTokenPath")
setCookie(config, res, legacyIdRefreshTokenCookieName, "", 0, "accessTokenPath", req, userContext)
}
}

Expand All @@ -399,21 +399,21 @@ func RefreshSessionInRequest(req *http.Request, res http.ResponseWriter, config

for _, tokenTransferMethod := range AvailableTokenTransferMethods {
if tokenTransferMethod != requestTokenTransferMethod && refreshTokens[tokenTransferMethod] != nil {
ClearSession(config, res, tokenTransferMethod)
ClearSession(config, res, tokenTransferMethod, req, userContext)
}
}

(*result).AttachToRequestResponse(sessmodels.RequestResponseInfo{
(*result).AttachToRequestResponseWithContext(sessmodels.RequestResponseInfo{
Res: res,
Req: req,
TokenTransferMethod: requestTokenTransferMethod,
})
}, userContext)

supertokens.LogDebugMessage("refreshSession: Success!")

if GetCookieValue(req, legacyIdRefreshTokenCookieName) != nil {
supertokens.LogDebugMessage("refreshSession: cleared legacy id refresh token after successful refresh")
setCookie(config, res, legacyIdRefreshTokenCookieName, "", 0, "accessTokenPath")
setCookie(config, res, legacyIdRefreshTokenCookieName, "", 0, "accessTokenPath", req, userContext)
}

return result, nil
Expand Down

0 comments on commit ace4b09

Please sign in to comment.