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
}
jc.ResponseWriter.Header().Set("Authorization", "Bearer "+jwt)
jc.ResponseWriter.WriteHeader(http.StatusOK)
jc.Encode(&LoginResponse{
Token: jwt,
})
}
func (a AccountAPI) register(jc jape.Context) {

View File

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

View File

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