1 回答

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超9個贊
您的代碼應(yīng)該基于現(xiàn)有的視圖和序列化器rest_framework_simplejwt:使用TokenObtainPairView是一個好的開始,請保留它。
然后在你的seriliizer_class中MyTokenObtainPairSerializer,你應(yīng)該使用TokenObtainSerializer
class MyTokenObtainPairSerializer(TokenObtainPairSerializer):
def validate(self, attrs):
self.user = User.objects.get(phone_number=phone_number)
# Do the verification with the phone_code here, if error, return a response with an error status code
refresh = self.get_token(self.user)
data['refresh'] = text_type(refresh)
data['access'] = text_type(refresh.access_token)
return data
添加回答
舉報(bào)