I've come across this block of code where the model script is handling token verification:
def encode_auth_token(self, user_id): try: payload = { 'exp': datetime.datetime.utcnow() + datetime.timedelta( days=current_app.config.get('TOKEN_EXPIRATION_DAYS'), \ seconds=current_app.config.get('TOKEN_EXPIRATION_SECONDS')), 'iat': datetime.datetime.utcnow(), 'sub': user_id } return jwt.encode(payload, current_app.config.get('SECRET_KEY'), algorithm='HS256') except Exception as e: return e @staticmethod def decode_auth_token(token): try: return jwt.decode(token, current_app.config.get('SECRET_KEY')) except jwt.ExpiredSignatureError: return 'Signature expired. Please log in again.' except jwt.InvalidTokenError: return 'Invalid token. Please log in again.' My question to this block of code is why decode_auth_token method needs to be a static method whereas encode_auth_token doesn't need to be ?
self.self. At the same time, there's nothing wrong to make them both plain instance methods.encode_auth_tokenmethod does. It needs access to model's ID attribute.