From f5e41a40ec602f1520a96f1e3dc32e45ef9a8527 Mon Sep 17 00:00:00 2001 From: Benjamin Frost Date: Sun, 19 May 2024 13:05:03 +0200 Subject: [PATCH] feat: expose user id on auth --- DOCS.md | 3 ++- src/auth/auth.service.ts | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/DOCS.md b/DOCS.md index e585baf..6a2ffe6 100644 --- a/DOCS.md +++ b/DOCS.md @@ -10,7 +10,7 @@ This is the API documentation for the AEC 2024 Skill 08 Session 3 API. ## Authentication -The API uses a simple authentication mechanism. The user must provide a valid username in order to access the API. The username is sent as a JSON object in the request body. The API will respond with a JSON object containing a JSON Web Token (JWT) that must be included in the `Authorization` header of all subsequent requests using the `Bearer` scheme. +The API uses a simple authentication mechanism. The user must provide a valid username in order to access the API. The username is sent as a JSON object in the request body. The API will respond with a JSON Web Token (JWT) that must be included in the `Authorization` header of all subsequent requests using the `Bearer` scheme. Besides the JWT, the API will also respond with the user's ID which is required to access the authenticated user's profile.
View details @@ -31,6 +31,7 @@ Example Response ```json { + "id": 2, "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEsInVzZXJuYW1lIjoiYmVuamFtaW5fZnJvc3QiLCJpYXQiOjE3MTUwMjY5MjYsImV4cCI6MTcxNzYxODkyNn0.gAm5sI5V2gzIE49_RQAbgBW3zVINHCKd0xaRWT6bwKY" } ``` diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index ce9e235..569f253 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -26,6 +26,7 @@ export class AuthService { }; return { + id: user.id, access_token: await this.jwtService.signAsync(payload), }; }