Improve login/logout

Extract mutation types to mutation-types.js
This commit is contained in:
2022-01-25 20:30:47 +00:00
parent 6dcf7da861
commit 74c4c7cb02
5 changed files with 35 additions and 15 deletions

View File

@ -93,9 +93,10 @@ func (h *Handler) loginPost(c *gin.Context) {
go h.Service.UpdateLastLogin(context.Background(), user.ID)
c.JSON(http.StatusOK, map[string]string{
"token": t,
})
c.JSON(http.StatusOK, struct {
Token string
User postgres.User
}{t, user})
}
type registerInformation struct {
@ -130,8 +131,20 @@ func (h *Handler) registerPost(c *gin.Context) {
Password: hash,
Email: register.Email,
}
_, err = h.Service.CreateUser(c.Request.Context(), createUser)
user, err := h.Service.CreateUser(c.Request.Context(), createUser)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
}
t, err := h.TokenVerifier.CreateToken(&user)
if err != nil {
c.AbortWithError(http.StatusUnauthorized, err)
}
go h.Service.UpdateLastLogin(context.Background(), user.ID)
c.JSON(http.StatusOK, struct {
Token string
User postgres.User
}{t, user})
}