2025-11-24 01:00:50 +01:00
|
|
|
import type { TProfile, TUser } from '@cio/db/types';
|
|
|
|
|
|
2025-09-10 20:39:16 +01:00
|
|
|
import { writable } from 'svelte/store';
|
2023-10-29 12:07:34 +00:00
|
|
|
|
2023-12-05 08:31:26 +03:00
|
|
|
interface UserStore {
|
2023-10-29 12:07:34 +00:00
|
|
|
openAuthModal: boolean;
|
|
|
|
|
fetchingUser: boolean;
|
|
|
|
|
isLoggedIn: boolean;
|
2025-11-24 01:00:50 +01:00
|
|
|
currentSession: TUser | undefined;
|
2023-10-29 12:07:34 +00:00
|
|
|
expiresAt: number;
|
2023-12-05 08:31:26 +03:00
|
|
|
}
|
2023-10-29 12:07:34 +00:00
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
// Using TProfile type from @cio/utils/types with optional id for store initialization
|
|
|
|
|
export type ProfileStore = Omit<TProfile, 'id'> & {
|
2023-10-30 04:52:00 +00:00
|
|
|
id: string | undefined;
|
2025-11-24 01:00:50 +01:00
|
|
|
};
|
2023-12-05 08:31:26 +03:00
|
|
|
|
|
|
|
|
export const defaultUserState: UserStore = {
|
|
|
|
|
openAuthModal: false,
|
2025-09-10 20:39:16 +01:00
|
|
|
fetchingUser: true,
|
2023-12-05 08:31:26 +03:00
|
|
|
isLoggedIn: false,
|
|
|
|
|
currentSession: undefined,
|
|
|
|
|
expiresAt: 0
|
|
|
|
|
};
|
|
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
export const defaultProfileState: TProfile = {
|
|
|
|
|
id: '',
|
2023-10-29 12:07:34 +00:00
|
|
|
fullname: '',
|
2025-11-24 01:00:50 +01:00
|
|
|
avatarUrl: '',
|
2024-11-12 12:37:25 +01:00
|
|
|
username: '',
|
2025-11-24 01:00:50 +01:00
|
|
|
email: null,
|
|
|
|
|
role: null,
|
|
|
|
|
goal: null,
|
|
|
|
|
source: null,
|
|
|
|
|
telegramChatId: null,
|
|
|
|
|
locale: 'en',
|
|
|
|
|
isEmailVerified: false,
|
|
|
|
|
verifiedAt: null,
|
|
|
|
|
canAddCourse: true,
|
|
|
|
|
isRestricted: false,
|
|
|
|
|
createdAt: '',
|
|
|
|
|
updatedAt: '',
|
|
|
|
|
metadata: null
|
2023-12-05 08:31:26 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const user = writable<UserStore>(defaultUserState);
|
|
|
|
|
|
2025-11-24 01:00:50 +01:00
|
|
|
export const profile = writable<TProfile>(defaultProfileState);
|