Vue js Django Rest Framework With JWT user authentication (getting anonymous user ) simplejwt

大兔子大兔子 提交于 2021-01-29 11:13:49

问题


I got the token.But it is not possible to get data this user. which URL to get data . token work. //simplejwt simplejwt

class CustomerRetrieveView(generics.RetrieveAPIView):

    queryset = Customer.objects.all()
    permission_classes=(IsAuthenticated,)
    def get(self,request):
                                   ???here correct?????
        queryset=Customer.objects.get(id=request.user)
        serializer=CustomerSerializer(queryset)
        
        return Response(serializer.data)

url

                ??here correct?????
path('customers/????<int:id>???', views.CustomerRetrieveView.as_view()),
frontend

created() { 
      getAPI.get('???????????/customers????????', { headers: { Authorization: `Bearer ${this.$store.state.accessToken}` } })
      .then(response => {
        this.$store.state.APIData = response.data
      })
      .catch(err => {
        console.log(err)
        console.log(`Bearer ${this.$store.state.accessToken}`)
      })

      
        
     
        
        
        
    },

models

class Customer(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    phone = models.CharField(max_length=11)
    likecus=models.ManyToManyField(smartphone ,verbose_name="b")

    def __str__(self):
        return "User: {}, phone: {}".format(self.user, self.phone)

Serializer

class CustomerSerializer(serializers.ModelSerializer):
   

    class Meta:
        model = Customer
        fields = '__all__'

I got the token.But it is not possible to get data this user. which URL to get data . token workI got the token.But it is not possible to get data this user. which URL to get data . token workI got the token.But it is not possible to get data this user. which URL to get data . token work

来源:https://stackoverflow.com/questions/65601221/vue-js-django-rest-framework-with-jwt-user-authentication-getting-anonymous-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!