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
|
||||
@@ -46,23 +46,23 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
const register = async (userData) => {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
|
||||
|
||||
try {
|
||||
const response = await axios.post(`${API_BASE_URL}/register`, userData)
|
||||
|
||||
|
||||
// После успешной регистрации автоматически логинимся
|
||||
const loginResponse = await axios.post(`${API_BASE_URL}/login`, {
|
||||
email: userData.email,
|
||||
password: userData.password
|
||||
})
|
||||
|
||||
|
||||
const { token: authToken, user: userInfo } = loginResponse.data
|
||||
setToken(authToken)
|
||||
setUser(userInfo)
|
||||
|
||||
|
||||
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
|
||||
@@ -73,14 +73,14 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
const login = async (credentials) => {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
|
||||
|
||||
try {
|
||||
const response = await axios.post(`${API_BASE_URL}/login`, credentials)
|
||||
const { token: authToken, user: userInfo } = response.data
|
||||
|
||||
|
||||
setToken(authToken)
|
||||
setUser(userInfo)
|
||||
|
||||
|
||||
return { success: true, data: response.data }
|
||||
} catch (err) {
|
||||
error.value = err.response?.data?.message || 'Ошибка входа'
|
||||
@@ -93,7 +93,7 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
// Выход
|
||||
const logout = async () => {
|
||||
loading.value = true
|
||||
|
||||
|
||||
try {
|
||||
await axios.post(`${API_BASE_URL}/logout`, {}, {
|
||||
headers: {
|
||||
@@ -113,7 +113,7 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
const fetchProfile = async () => {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
|
||||
|
||||
try {
|
||||
const response = await axios.get(`${API_BASE_URL}/profile`)
|
||||
setUser(response.data)
|
||||
@@ -144,11 +144,11 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
token,
|
||||
loading,
|
||||
error,
|
||||
|
||||
|
||||
// Getters
|
||||
isAuthenticated,
|
||||
userFullName,
|
||||
|
||||
|
||||
// Actions
|
||||
register,
|
||||
login,
|
||||
|
||||
Reference in New Issue
Block a user