AuthResponse.java
Springboot/bookstore-api/src/main/java/com/example/bookstore/dto/AuthResponse.java
package com.example.bookstore.dto;
/**
* 「登入成功」的回應 DTO——把 JWT 交給客戶端。
*
* 客戶端收到後應妥善保存 token,
* 之後每次呼叫受保護的 API 時,都要在 HTTP Header 加上:
*
* Authorization: Bearer <token>
*
* 回應範例:
* {
* "token": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyIi...",
* "tokenType": "Bearer",
* "expiresIn": 3600,
* "username": "user",
* "role": "ROLE_USER"
* }
*/
public record AuthResponse(
String token, // JWT 字串本體
String tokenType, // 固定為 "Bearer"(HTTP 認證方案名稱)
long expiresIn, // 有效秒數(方便客戶端判斷何時該重新登入)
String username, // 登入者帳號
String role // 登入者角色(方便前端顯示對應介面)
) {
}
Articoli correlati
BookstoreApiApplication.java
BookstoreApiApplication.java — java source code from the Springboot learning materials (Springboot/bookstore-api/src/main/java/com/example/bookstore/BookstoreApiApplication.java).
Leggi l'articolo →DataInitializer.java
DataInitializer.java — java source code from the Springboot learning materials (Springboot/bookstore-api/src/main/java/com/example/bookstore/config/DataInitializer.java).
Leggi l'articolo →SecurityConfig.java
SecurityConfig.java — java source code from the Springboot learning materials (Springboot/bookstore-api/src/main/java/com/example/bookstore/config/SecurityConfig.java).
Leggi l'articolo →AuthController.java
AuthController.java — java source code from the Springboot learning materials (Springboot/bookstore-api/src/main/java/com/example/bookstore/controller/AuthController.java).
Leggi l'articolo →BookController.java
BookController.java — java source code from the Springboot learning materials (Springboot/bookstore-api/src/main/java/com/example/bookstore/controller/BookController.java).
Leggi l'articolo →ApiErrorResponse.java
ApiErrorResponse.java — java source code from the Springboot learning materials (Springboot/bookstore-api/src/main/java/com/example/bookstore/dto/ApiErrorResponse.java).
Leggi l'articolo →