feat(auth): add user profile, phone login, and account deletion

This commit is contained in:
iu
2026-10-12 14:26:32 +03:00
parent 1cb9aaf198
commit 86aff695df
46 changed files with 2893 additions and 134 deletions
+12 -4
View File
@@ -86,19 +86,27 @@ export async function api<T = unknown>(path: string, opts: RequestOptions = {}):
}
export const authApi = {
register: (email: string, password: string, name: string) =>
register: (email: string, phone: string, password: string, name: string) =>
api<{ user: User; tokens: Tokens }>('/auth/register', {
method: 'POST',
body: { email, password, name }
body: { email, phone, password, name }
}),
login: (email: string, password: string) =>
login: (identifier: string, password: string) =>
api<{ user: User; tokens: Tokens }>('/auth/login', {
method: 'POST',
body: { email, password }
body: { identifier, password }
}),
logout: (refresh_token: string) =>
api('/auth/logout', { method: 'POST', body: { refresh_token } }),
me: () => api<{ user: User; preferences?: Preferences }>('/auth/me'),
updateProfile: (name: string) =>
api<{ user: User }>('/auth/me', { method: 'PATCH', body: { name } }),
changePassword: (current_password: string, new_password: string) =>
api('/auth/me/password', { method: 'POST', body: { current_password, new_password } }),
addIdentifier: (email: string, phone: string) =>
api<{ user: User }>('/auth/me/identifiers', { method: 'POST', body: { email, phone } }),
deleteAccount: (password: string) =>
api('/auth/me', { method: 'DELETE', body: { password } }),
savePreferences: (preferences: Preferences) =>
api<{ preferences: Preferences }>('/auth/me/preferences', {
method: 'PATCH',
+8 -1
View File
@@ -133,7 +133,14 @@
</button>
{/if}
{#if auth.isAuthenticated}
<span class="text-text-muted hidden text-xs sm:inline">{auth.user?.name ?? ''}</span>
<a
href="/profile"
class="text-text-muted hover:text-text inline-flex items-center gap-1 text-xs"
title="Профиль"
>
<Icon name="settings" class="size-4" />
<span class="hidden sm:inline">{auth.user?.name ?? 'Профиль'}</span>
</a>
<button
type="button"
class="text-text-muted hover:text-text inline-flex items-center gap-1 text-xs"
+2 -1
View File
@@ -2,7 +2,8 @@ import type { Preferences } from '$lib/types';
export interface User {
id: string;
email: string;
email?: string;
phone?: string;
name: string;
avatar_url?: string;
preferences?: Preferences;
+1
View File
@@ -10,6 +10,7 @@ export interface Preferences {
export interface User {
id: string;
email?: string;
phone?: string;
name: string;
avatar_url?: string;
preferences?: Preferences;