identity-service/internal/app/handler/auth.go

36 lines
937 B
Go
Raw Normal View History

2022-06-19 15:19:05 +02:00
package handler
import (
"net/http"
def "git.pbiernat.dev/egommerce/application/services/identity/internal/app/definition"
"git.pbiernat.dev/egommerce/application/services/identity/internal/app/service"
)
var AuthLoginHandler *Handler
func init() {
AuthLoginHandler = &Handler{
Handle: AuthLoginHandlerFunc,
Request: &def.AuthLoginRequest{},
Response: &def.AuthLoginResponse{},
}
}
func AuthLoginHandlerFunc(h *Handler, w http.ResponseWriter) (interface{}, int, error) {
var req = h.Request.(*def.AuthLoginRequest)
// u := entity.TestUser
token, err := service.AuthService.Login(req)
if err != nil {
return nil, http.StatusUnauthorized, err
}
service.AuthService.SetCookie(w, service.AuthService.TokenCookieName, token)
// service.AuthService.SetCookie(w, service.AuthService.RefreshTokenCookieName, refreshTtoken)
// log.Println("user:", u, "req:", token, "err:", err)
return nil, http.StatusOK, nil
}