new file: begushiybashkir/bbvue/.env
modified: begushiybashkir/bbvue/src/stores/auth.js modified: serv_nginx/api_bb/internal/handlers/auth.go fix auth api_bb for debug info
This commit is contained in:
@@ -0,0 +1 @@
|
||||
VITE_APP_DEBUG=true
|
||||
@@ -62,7 +62,7 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
|
||||
return { success: true, data: response.data }
|
||||
} catch (err) {
|
||||
error.value = err.response?.data?.message || 'Ошибка регистрации'
|
||||
error.value = err.response?.data?.message || err.message || 'Ошибка регистрации'
|
||||
return { success: false, error: error.value }
|
||||
} finally {
|
||||
loading.value = false
|
||||
|
||||
@@ -83,22 +83,50 @@ type UserResponse struct {
|
||||
}
|
||||
|
||||
func (h *AuthHandler) Register(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
fmt.Printf("Register request: %+v\n", r)
|
||||
|
||||
// Устанавливаем CORS заголовки
|
||||
w.Header().Set("Access-Control-Allow-Origin", r.Header.Get("Origin"))
|
||||
w.Header().Set("Access-Control-Allow-Credentials", "true")
|
||||
|
||||
var req RegisterRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
utils.RespondWithError(w, http.StatusBadRequest, "Invalid request payload: "+err.Error())
|
||||
// Логируем тело запроса для отладки
|
||||
bodyBytes, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
utils.RespondWithError(w, http.StatusBadRequest, "Failed to read request body: "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// Восстанавливаем тело для дальнейшего использования
|
||||
r.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
|
||||
|
||||
fmt.Printf("Raw request body: %s\n", string(bodyBytes))
|
||||
|
||||
var req RegisterRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
fmt.Printf("JSON decode error: %v\n", err)
|
||||
utils.RespondWithError(w, http.StatusBadRequest, "Invalid JSON payload: "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("Parsed register request: %+v\n", req)
|
||||
|
||||
// Валидация обязательных полей
|
||||
if req.FirstName == "" || req.LastName == "" || req.Email == "" || req.Password == "" {
|
||||
utils.RespondWithError(w, http.StatusBadRequest, "First name, last name, email and password are required")
|
||||
if req.FirstName == "" {
|
||||
utils.RespondWithError(w, http.StatusBadRequest, "First name is required")
|
||||
return
|
||||
}
|
||||
if req.LastName == "" {
|
||||
utils.RespondWithError(w, http.StatusBadRequest, "Last name is required")
|
||||
return
|
||||
}
|
||||
if req.Email == "" {
|
||||
utils.RespondWithError(w, http.StatusBadRequest, "Email is required")
|
||||
return
|
||||
}
|
||||
if req.Password == "" {
|
||||
utils.RespondWithError(w, http.StatusBadRequest, "Password is required")
|
||||
return
|
||||
}
|
||||
if len(req.Password) < 6 {
|
||||
utils.RespondWithError(w, http.StatusBadRequest, "Password must be at least 6 characters")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -117,6 +145,7 @@ func (h *AuthHandler) Register(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if err := h.authService.Register(user); err != nil {
|
||||
fmt.Printf("Auth service error: %v\n", err)
|
||||
utils.RespondWithError(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user