@@ -164,7 +164,7 @@ def create_session(response, data=None):
164164def before_request ():
165165 # TODO: Fix circular import
166166 from framework .auth .core import get_user
167- from framework .auth import cas , utils
167+ from framework .auth import cas
168168 UserSessionMap = apps .get_model ('osf.UserSessionMap' )
169169
170170 # Request Type 1: Service ticket validation during CAS login.
@@ -215,8 +215,15 @@ def before_request():
215215 try :
216216 user_session = flask_get_session_from_cookie (cookie )
217217 except InvalidCookieOrSessionError :
218- # If invalid session/cookie happens, perform a full logout to clear both CAS and OSF Sessions
219- response = redirect (utils .get_default_osf_logout_url ())
218+ # If invalid session/cookie happens, only remove the invalid cookie and redirect to the same request.
219+ # This ensures users landing on the page/link they previously clicked.
220+ # Case 1: If it's a public page, they land on the correct page.
221+ # Case 2: If it's a private page and if they already have a CAS cookie, they will be automatically logged
222+ # back in and land on the correct page.
223+ # Case 3: If it's a private page and if they don't have a CAS cookie, they will need to manually log in.
224+ # After successful login, they will land on the correct page.
225+ redirect_url = request .url
226+ response = redirect (redirect_url )
220227 response .delete_cookie (settings .COOKIE_NAME , domain = settings .OSF_COOKIE_DOMAIN )
221228 return response
222229 # Case 1: anonymous session that is used for first time external (e.g. ORCiD) login only
0 commit comments