@@ -187,16 +187,16 @@ <h1 class="title">Module <code>supertokens_python.recipe.session.with_jwt.recipe
187187 if decoded_payload is None or decoded_payload.get("exp") is None:
188188 raise Exception("Error reading JWT from session")
189189
190- jwt_expiry = 1
191- if "exp" in decoded_payload:
192- exp = decoded_payload["exp"]
193- if exp > current_time_in_seconds:
194- # it can come here if someone calls this function well after
195- # the access token and the jwt payload have expired. In this case,
196- # we still want the jwt payload to update, but the resulting JWT should
197- # not be alive for too long (since it's expired already). So we set it to
198- # 1 second lifetime.
199- jwt_expiry = exp - current_time_in_seconds
190+ jwt_expiry = decoded_payload.get("exp", 0) - current_time_in_seconds
191+ # pylint: disable=consider-using-max-builtin
192+ if jwt_expiry < 1:
193+ # it can come here if someone calls this function well after
194+ # the access token and the jwt payload have expired. In this case,
195+ # we still want the jwt payload to update, but the resulting JWT should
196+ # not be alive for too long (since it's expired already). So we set it to
197+ # 1 second lifetime.
198+ jwt_expiry = 1
199+ # pylint: enable=consider-using-max-builtin
200200
201201 new_access_token_payload = await add_jwt_to_access_token_payload(
202202 access_token_payload=new_access_token_payload,
@@ -405,16 +405,16 @@ <h2 class="section-title" id="header-functions">Functions</h2>
405405 if decoded_payload is None or decoded_payload.get("exp") is None:
406406 raise Exception("Error reading JWT from session")
407407
408- jwt_expiry = 1
409- if "exp" in decoded_payload:
410- exp = decoded_payload["exp"]
411- if exp > current_time_in_seconds:
412- # it can come here if someone calls this function well after
413- # the access token and the jwt payload have expired. In this case,
414- # we still want the jwt payload to update, but the resulting JWT should
415- # not be alive for too long (since it's expired already). So we set it to
416- # 1 second lifetime.
417- jwt_expiry = exp - current_time_in_seconds
408+ jwt_expiry = decoded_payload.get("exp", 0) - current_time_in_seconds
409+ # pylint: disable=consider-using-max-builtin
410+ if jwt_expiry < 1:
411+ # it can come here if someone calls this function well after
412+ # the access token and the jwt payload have expired. In this case,
413+ # we still want the jwt payload to update, but the resulting JWT should
414+ # not be alive for too long (since it's expired already). So we set it to
415+ # 1 second lifetime.
416+ jwt_expiry = 1
417+ # pylint: enable=consider-using-max-builtin
418418
419419 new_access_token_payload = await add_jwt_to_access_token_payload(
420420 access_token_payload=new_access_token_payload,
0 commit comments