mirror of
https://github.com/ferdzo/iotDashboard.git
synced 2026-04-05 09:06:26 +00:00
24 lines
620 B
Python
24 lines
620 B
Python
"""
|
|
Custom JWT serializers for IoT Dashboard.
|
|
Handles string-based user IDs instead of integer IDs.
|
|
"""
|
|
|
|
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
|
|
from rest_framework_simplejwt.tokens import RefreshToken
|
|
|
|
|
|
class CustomTokenObtainPairSerializer(TokenObtainPairSerializer):
|
|
"""
|
|
Custom token serializer that handles string user IDs.
|
|
"""
|
|
|
|
@classmethod
|
|
def get_token(cls, user):
|
|
token = RefreshToken.for_user(user)
|
|
|
|
# Add custom claims
|
|
token['username'] = user.username
|
|
token['email'] = user.email
|
|
|
|
return token
|