Get currenty logged in user in Django/Angular

Discussão em 'Angular' iniciado por 0xDukis, Novembro 20, 2024.

  1. 0xDukis

    0xDukis Guest

    I am creating a Django / Angular project but I am having an issue. In normal django applications without frontend framework we can just do request.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

    Continue reading...

Compartilhe esta Página