Skip to content

feat(auth): document refresh endpoint response dto#368

Merged
vic-Gray merged 2 commits into
code-flexing:mainfrom
Depo-dev:feat/token-response-dto-317
May 29, 2026
Merged

feat(auth): document refresh endpoint response dto#368
vic-Gray merged 2 commits into
code-flexing:mainfrom
Depo-dev:feat/token-response-dto-317

Conversation

@Depo-dev
Copy link
Copy Markdown
Contributor

Summary

The POST /auth/refresh endpoint's TokenResponseDto was missing the token_type field. Per OAuth 2.0 convention (RFC 6750), token responses should include token_type: "Bearer" so that consumers know how to send the token in the Authorization header. Without it, API consumers had to infer the token type from convention alone, with no contract to rely on.

DTO Changes Made

dto/auth-response.dto.tsTokenResponseDto

  • Added token_type: string field with full @ApiProperty decorator documenting its value ("Bearer") and purpose

auth.service.tsrefresh() method

  • Now returns { access_token, token_type: 'Bearer' } so the actual response matches the DTO contract
  • Also applied a pre-existing build fix: explicit User | null annotation on the resetPassword loop accumulator (was causing TS2322 under strictNullChecks)

auth.controller.tsPOST /auth/refresh

  • Added missing @ApiResponse({ status: 400 }) decorator to document validation errors when refresh_token is missing or malformed (consistent with how /register documents its 400 responses)

Swagger / Response-field Verification

Before this change, the Swagger schema for POST /auth/refresh showed only access_token. After, it shows both access_token and token_type, and the service response matches the schema exactly.

Tests Added/Updated

auth.service.spec.ts

  • Added assertion: expect(result).toHaveProperty('token_type', 'Bearer') to the refresh success test

  • Fixed resetPassword tests to use find mock (was incorrectly mocking findOne)

  • npx jest auth.service.spec.ts — 12/12 passing

  • npm run build — clean

Fixes #317
Fixes #614

Add token_type field to TokenResponseDto and the refresh() service
method. The OAuth 2.0 convention requires token_type: 'Bearer' in
token responses so that consumers know how to send the token in the
Authorization header. Previously this field was absent from both the
service response and the DTO, leaving API consumers to infer the
token type from convention alone.

Changes:
- TokenResponseDto: add token_type field with ApiProperty decorator
  documenting its value and usage
- auth.service.ts refresh(): return token_type: 'Bearer' alongside
  access_token; also add explicit User | null type annotation to fix
  a pre-existing build error in the resetPassword method
- auth.controller.ts: add missing @apiresponse({ status: 400 })
  decorator to the refresh endpoint; Prettier formatting applied
- auth.service.spec.ts: assert token_type === 'Bearer' in the
  refresh success test; fix resetPassword tests to use find mock
  instead of the incorrect findOne mock

Fixes code-flexing#317
Fixes #614
@vercel
Copy link
Copy Markdown

vercel Bot commented May 29, 2026

@Depo-dev is attempting to deploy a commit to the vic's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 29, 2026

@Depo-dev Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@vic-Gray vic-Gray merged commit a4c2298 into code-flexing:main May 29, 2026
1 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#614 Add response DTO for token refresh endpoint

2 participants