Get Current User
Guide on how to retrieve the currently authenticated user via the API endpoint `api/auth/me`.
To retrieve information about the currently authenticated user, you need to make a GET
request to the api/auth/me
endpoint. The request should include the Authorization
header with a valid authentication token.
How to change the 'me' endpoint?
You can change the endpoint by modifying ME_ENDPOINT
in settings.py
.
Endpoint
- URL:
api/auth/me
- Method:
GET
- Content-Type:
application/json
- Headers:
Authorization: Bearer <token>
Example Request
Here is an example of how to make a GET request using curl
:
curl -X GET "http://yourapi.com/api/auth/me" \
-H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxfQ"
Example Response
{
"id": 1,
"username": "john_doe",
"email": "john@example.com",
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxfQ"
}
Built-in login view
The code below shows the logic for getting the current user.
from blazingapi.app import app
from blazingapi.response import Response
from blazingapi.settings import settings
from blazingapi.auth.permissions import IsAuthenticated
@app.get(settings.ME_ENDPOINT, permissions=[IsAuthenticated])
def me(request):
return Response(body=request.user, status=200)