Add offline fallback for getCurrentUser
cgen-0af0f00859284cc28d3665d5afdcfd5b
This commit is contained in:
parent
af6ee133a8
commit
de14690090
1 changed files with 31 additions and 0 deletions
|
|
@ -267,6 +267,37 @@ function isTableMissing(err: any): boolean {
|
||||||
// User Profile Services
|
// User Profile Services
|
||||||
export const aethexUserService = {
|
export const aethexUserService = {
|
||||||
async getCurrentUser(): Promise<AethexUserProfile | null> {
|
async getCurrentUser(): Promise<AethexUserProfile | null> {
|
||||||
|
if (!isSupabaseConfigured) {
|
||||||
|
const { data } = await mockAuth.getUser();
|
||||||
|
const user = data.user;
|
||||||
|
if (!user) return null;
|
||||||
|
|
||||||
|
const profile = await mockAuth.getUserProfile(user.id);
|
||||||
|
if (!profile || Object.keys(profile || {}).length === 0) {
|
||||||
|
return await this.createInitialProfile(
|
||||||
|
user.id,
|
||||||
|
{
|
||||||
|
username: user.email?.split("@")[0] || "user",
|
||||||
|
full_name: user.email?.split("@")[0] || "user",
|
||||||
|
},
|
||||||
|
user.email,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalized = normalizeProfile(
|
||||||
|
{
|
||||||
|
...profile,
|
||||||
|
user_type: (profile as any)?.user_type ?? "game_developer",
|
||||||
|
experience_level: (profile as any)?.experience_level ?? "beginner",
|
||||||
|
total_xp: (profile as any)?.total_xp ?? 0,
|
||||||
|
level: (profile as any)?.level ?? 1,
|
||||||
|
},
|
||||||
|
user.email ?? (profile as any)?.email ?? null,
|
||||||
|
);
|
||||||
|
|
||||||
|
return await ensureDailyStreakForProfile(normalized);
|
||||||
|
}
|
||||||
|
|
||||||
ensureSupabase();
|
ensureSupabase();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue