Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3672

Get currenty logged in user in Django/Angular

$
0
0

I am creating a Django / Angular project but I am having an issue.In normal django applications without frontend framework we can just dorequest.user and we can get the iformation needed. I already created the api endpoints to my User model but is there a way to directly find the user Id to make a call like this:

  getUserById(userId: number): Observable<User> {    const url = `${this.baseUrl}users/${userId}/`;    return this.http.get<User>(url);  }

Or do I need to set up a different serializer like this for example:

class CurrentUserView(APIView):    permission_classes = [IsAuthenticated]     def get(self, request):        user = request.user  # Get the current logged-in user        serializer = UserSerializer(user)        return Response(serializer.data)

make a call to this endpoint and then with the data from here access the rest of the endpoints?Also right now I havent set up an Authentication mechanism. Maybe in the future if I do I wont be needing an endpoint like this?Thanks in advance


Viewing all articles
Browse latest Browse all 3672

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>