feat(api): auth-хендлеры register/login/logout/me + session cookie
This commit is contained in:
+38
-1
@@ -1,6 +1,43 @@
|
||||
package api
|
||||
|
||||
import "github.com/vasyakrg/dns-autoresolver/internal/diff"
|
||||
import (
|
||||
"github.com/vasyakrg/dns-autoresolver/internal/diff"
|
||||
"github.com/vasyakrg/dns-autoresolver/internal/store"
|
||||
)
|
||||
|
||||
type registerRequest struct {
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type loginRequest struct {
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
// userResponse and projectResponse deliberately expose only id/email and
|
||||
// id/name — password_hash must never reach a client response.
|
||||
type userResponse struct {
|
||||
ID string `json:"id"`
|
||||
Email string `json:"email"`
|
||||
}
|
||||
|
||||
type projectResponse struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type authResponse struct {
|
||||
User userResponse `json:"user"`
|
||||
Project projectResponse `json:"project"`
|
||||
}
|
||||
|
||||
func toAuthResponse(u store.User, p store.Project) authResponse {
|
||||
return authResponse{
|
||||
User: userResponse{ID: u.ID.String(), Email: u.Email},
|
||||
Project: projectResponse{ID: p.ID.String(), Name: p.Name},
|
||||
}
|
||||
}
|
||||
|
||||
type applyRequest struct {
|
||||
ApplyUpdates bool `json:"applyUpdates"`
|
||||
|
||||
Reference in New Issue
Block a user