diff --git a/http/session.go b/http/session.go index e82c467..5f61b38 100644 --- a/http/session.go +++ b/http/session.go @@ -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}) } diff --git a/web/src/App.vue b/web/src/App.vue index 6cbb940..649a4f4 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -1,5 +1,8 @@