Improve login/logout
Extract mutation types to mutation-types.js
This commit is contained in:
@ -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})
|
||||
}
|
||||
|
Reference in New Issue
Block a user