refactor: change login to respond with the jwt token in the body
This commit is contained in:
parent
550398c701
commit
91d58ee87f
|
@ -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) {
|
||||||
|
|
|
@ -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"`
|
||||||
|
|
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue