jpadilla / django-rest-framework-jwt

JSON Web Token Authentication support for Django REST Framework
http://jpadilla.github.io/django-rest-framework-jwt/
MIT License
3.19k stars 649 forks source link

Token Questions #300

Closed Chuck-Aguilar closed 7 years ago

Chuck-Aguilar commented 7 years ago

HI! I really appreciate jwt.

I just wanna know a few things.

First, I make the login with the email and password, and I get the token. It works well.

but I also wanna create a token in my register. so, I use this function:

def create_token(user):
    jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
    jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER

    payload = jwt_payload_handler(user)
    token = jwt_encode_handler(payload)

    return token

The problem is that I don't have an username. So, it doesn't work. :) I thought, if it works with the login, it should work with the register. But not. :smiley:

Even if I wrote this USERNAME_FIELD = 'email' in my model. It always asks for a username in my "create_token" function.

But second, I would like to create the token with just the email, password, and uuid

And third... Is the same token from my register and from my login? To make the requests, it should be the same.

Thank you!

Chuck-Aguilar commented 7 years ago

I already found the answer. In the docs it's well explained.