Skip to content

Get Current Admin (Me)

Method

REST method is adopted.

HTTP Method

GET: Get current authenticated admin

Naming Convention

To unify naming of query parameters and nodes and improve readability, snake_case is used for URIs and nodes in JSON during requests.

Request and Response

Headers

Meta information is set in HTTP headers rather than in the response body.

Request Headers

  • Authorization: Bearer <access_token>
  • Content-Type: application/json
  • Accept: application/json

Response Headers

  • Content-Type: application/json

Get Current Admin

URI

/api/v1/auth/me

Response (200 OK)

Response is JSON.

{
  "admin": {
    "id": 1,
    "cognito_sub": "1111-aaaa-2222-bbbb",
    "role_id": 1,
    "name": "Admin User",
    "created_at": 1640995200000,
    "updated_at": 1640995200000,
    "created_by": "1111-aaaa-2222-bbbb",
    "updated_by": "1111-aaaa-2222-bbbb",
    "deleted_at": null,
    "deleted_by": null,
    "role": {
      "id": 1,
      "name": "admin"
    }
  }
}

Authentication

Authentication is performed using JSON Web Tokens (JWT) issued by Amazon Cognito. A valid Bearer token is required in the Authorization header.

Exception Handling

Exception handling status codes are as follows.

Description Status Code Status Name
Missing or invalid token 401 Unauthorized
Internal server error 500 Internal Server Error

Process Flow

Sequence Diagram

sequenceDiagram
    participant Client
    participant Middleware as Protected Route Middleware
    participant API as Hono Router
    participant Service as Auth Service
    participant DB as PostgreSQL Database

    Client->>Middleware: GET /api/v1/auth/me
    Middleware->>Middleware: Extract Bearer token
    Middleware->>Middleware: Verify JWT & session

    alt Token Valid
        Middleware-->>API: Auth info (sub, adminId)
        API->>Service: getMe(cognitoSub)
        Service->>DB: Find admin by cognito_sub
        DB-->>Service: Admin record with role
        Service-->>API: Admin with relations
        API-->>Client: 200 OK { admin }
    else Token Invalid
        Middleware-->>Client: 401 Unauthorized
    end

Routes Layer

API routing is performed here. The protectedRoute middleware validates the JWT token and session before the handler executes. The handler extracts the authenticated user's info and delegates to the auth service.

Source: apps/admin/src/routes/v1/auth.ts

Services Layer

This section describes business logic. It looks up the admin record by Cognito sub, including the associated role, and returns the formatted admin data.

Source: apps/admin/src/services/auth.ts

Repositories Layer

This section describes access to databases. It handles admin lookup by Cognito sub with role relation.

Source: apps/admin/src/repositories/admin.ts

Security

  • Token validated by protectedRoute middleware before handler execution
  • Session existence verified via verifySession
  • Returns full admin profile including role for frontend authorization decisions