refactor: change login to respond with the jwt token in the body

This commit is contained in:
Derrick Hammer 2024-03-06 18:11:34 -05:00
parent 550398c701
commit 91d58ee87f
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 15 additions and 6 deletions

View File

@ -108,8 +108,9 @@ func (a AccountAPI) login(jc jape.Context) {
return return
} }
jc.ResponseWriter.Header().Set("Authorization", "Bearer "+jwt) jc.Encode(&LoginResponse{
jc.ResponseWriter.WriteHeader(http.StatusOK) Token: jwt,
})
} }
func (a AccountAPI) register(jc jape.Context) { func (a AccountAPI) register(jc jape.Context) {

View File

@ -5,6 +5,10 @@ type LoginRequest struct {
Password string `json:"password"` Password string `json:"password"`
} }
type LoginResponse struct {
Token string `json:"token"`
}
type RegisterRequest struct { type RegisterRequest struct {
FirstName string `json:"first_name"` FirstName string `json:"first_name"`
LastName string `json:"last_name"` LastName string `json:"last_name"`

View File

@ -16,11 +16,10 @@ paths:
responses: responses:
'200': '200':
description: Successfully logged in description: Successfully logged in
headers: content:
Authorization: application/json:
schema: schema:
type: string $ref: '#/components/schemas/LoginResponse'
description: Bearer token for the session
'401': '401':
description: Unauthorized description: Unauthorized
/api/auth/register: /api/auth/register:
@ -132,6 +131,11 @@ components:
type: string type: string
password: password:
type: string type: string
LoginResponse:
type: object
properties:
token:
type: string
RegisterRequest: RegisterRequest:
type: object type: object
required: required: