mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 17:43:47 +00:00
Update auth.ts
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { create } from 'zustand'
|
import { create } from 'zustand'
|
||||||
import { persist } from 'zustand/middleware'
|
import { persist } from 'zustand/middleware'
|
||||||
import type { User } from '../types'
|
import type { RegisterResponse, User } from '../types'
|
||||||
import { authApi } from '../api/auth'
|
import { authApi } from '../api/auth'
|
||||||
import { apiClient } from '../api/client'
|
import { apiClient } from '../api/client'
|
||||||
import { tokenStorage, isTokenValid, tokenRefreshManager } from '../utils/token'
|
import { tokenStorage, isTokenValid, tokenRefreshManager } from '../utils/token'
|
||||||
@@ -33,7 +33,7 @@ interface AuthState {
|
|||||||
loginWithTelegram: (initData: string) => Promise<void>
|
loginWithTelegram: (initData: string) => Promise<void>
|
||||||
loginWithTelegramWidget: (data: TelegramWidgetData) => Promise<void>
|
loginWithTelegramWidget: (data: TelegramWidgetData) => Promise<void>
|
||||||
loginWithEmail: (email: string, password: string) => Promise<void>
|
loginWithEmail: (email: string, password: string) => Promise<void>
|
||||||
registerWithEmail: (email: string, password: string, firstName?: string, referralCode?: string) => Promise<void>
|
registerWithEmail: (email: string, password: string, firstName?: string, referralCode?: string) => Promise<RegisterResponse>
|
||||||
}
|
}
|
||||||
|
|
||||||
// Блокировка для предотвращения race condition при инициализации
|
// Блокировка для предотвращения race condition при инициализации
|
||||||
@@ -263,6 +263,8 @@ export const useAuthStore = create<AuthState>()(
|
|||||||
},
|
},
|
||||||
|
|
||||||
registerWithEmail: async (email, password, firstName, referralCode) => {
|
registerWithEmail: async (email, password, firstName, referralCode) => {
|
||||||
|
// Registration now returns message, not tokens
|
||||||
|
// User must verify email before they can login
|
||||||
const response = await authApi.registerEmailStandalone({
|
const response = await authApi.registerEmailStandalone({
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
@@ -270,14 +272,7 @@ export const useAuthStore = create<AuthState>()(
|
|||||||
language: navigator.language.split('-')[0] || 'ru',
|
language: navigator.language.split('-')[0] || 'ru',
|
||||||
referral_code: referralCode,
|
referral_code: referralCode,
|
||||||
})
|
})
|
||||||
tokenStorage.setTokens(response.access_token, response.refresh_token)
|
return response
|
||||||
set({
|
|
||||||
accessToken: response.access_token,
|
|
||||||
refreshToken: response.refresh_token,
|
|
||||||
user: response.user,
|
|
||||||
isAuthenticated: true,
|
|
||||||
})
|
|
||||||
get().checkAdminStatus()
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user