Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Understanding jwt_payload util method #298

Open
manjurulhoque opened this issue Mar 27, 2022 · 0 comments
Open

Understanding jwt_payload util method #298

manjurulhoque opened this issue Mar 27, 2022 · 0 comments

Comments

@manjurulhoque
Copy link

manjurulhoque commented Mar 27, 2022

Thank you for the project!

def jwt_payload(user, context=None):
    username = user.get_username()

    if hasattr(username, 'pk'):
        username = username.pk

    payload = {
        user.USERNAME_FIELD: username,
        'exp': datetime.utcnow() + jwt_settings.JWT_EXPIRATION_DELTA,
    }

It's the code snippet of the package to get jwt_payload. My understanding was get_username() will always return string as its value.

Code snippet from AbstractBaseUser class.
image

My question is why do we need to check the username hasattr pk? Will it return an object for some cases?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant