
import time
from typing import Dict
import jwt as pyjwt
from server.backend.schema.pydantic import settings

def signJWT(user_info: dict) -> str:
    payload = {
        "user_id":user_info.id,
        "expires": time.time() + settings.ACCESS_TOKEN_EXPIRE_SECONDS
    }
    token = pyjwt.encode(payload, settings.SECRET_KEY, algorithm=settings.ALGORITHM)
    return token
def decodeJWT(token: str) -> dict:
    try:
        decoded_token = pyjwt.decode(token, settings.SECRET_KEY, algorithms=[settings.ALGORITHM])
        return decoded_token if decoded_token["expires"] >= time.time() else None
    except:
        return {}