refactor(client): remove avatarType, add auth effects, simplify UserAvatar
This commit is contained in:
@@ -11,11 +11,15 @@ export type AuthUser = {
|
||||
lastName?: string | null
|
||||
gender?: string | null
|
||||
avatar?: string | null
|
||||
avatarType?: string | null
|
||||
avatarStyle?: string | null
|
||||
isAdmin?: boolean
|
||||
}
|
||||
|
||||
export type AuthMethod = {
|
||||
type: 'password' | 'vk' | 'yandex'
|
||||
active: boolean
|
||||
}
|
||||
|
||||
export const tokenSet = createEvent<string | null>()
|
||||
export const logout = createEvent()
|
||||
|
||||
@@ -72,7 +76,6 @@ export const verifyEmailChangeFx = createEffect(async (params: { newEmail: strin
|
||||
export type UpdateProfileParams = {
|
||||
displayName: string | null
|
||||
avatar?: string | null
|
||||
avatarType?: string | null
|
||||
avatarStyle?: string | null
|
||||
}
|
||||
|
||||
@@ -81,6 +84,35 @@ export const updateProfileFx = createEffect(async (params: UpdateProfileParams)
|
||||
return data.user
|
||||
})
|
||||
|
||||
// ----- Auth effects -----
|
||||
|
||||
export const loginFx = createEffect(async (params: { email: string; password: string }) => {
|
||||
const { data } = await apiClient.post<{ token: string; user: AuthUser }>('auth/login', params)
|
||||
tokenSet(data.token)
|
||||
return data.user
|
||||
})
|
||||
|
||||
export const registerFx = createEffect(
|
||||
async (params: { email: string; password: string; displayName?: string }) => {
|
||||
const { data } = await apiClient.post<{ token: string; user: AuthUser }>('auth/register', params)
|
||||
tokenSet(data.token)
|
||||
return data.user
|
||||
},
|
||||
)
|
||||
|
||||
export const fetchAuthMethodsFx = createEffect(async () => {
|
||||
const { data } = await apiClient.get<{ methods: AuthMethod[] }>('me/auth-methods')
|
||||
return data.methods
|
||||
})
|
||||
|
||||
export const setPasswordFx = createEffect(async (password: string) => {
|
||||
await apiClient.post('me/password', { password })
|
||||
})
|
||||
|
||||
export const unlinkOAuthFx = createEffect(async (provider: 'vk' | 'yandex') => {
|
||||
await apiClient.delete(`me/oauth/${provider}`)
|
||||
})
|
||||
|
||||
// ----- Error stores -----
|
||||
|
||||
export const $requestEmailChangeCodeError = createErrorStore(requestEmailChangeCodeFx).$error
|
||||
|
||||
Reference in New Issue
Block a user