Prettier format pending files
This commit is contained in:
parent
b687f4de04
commit
144f975e7e
2 changed files with 58 additions and 40 deletions
|
|
@ -32,19 +32,19 @@ class MockAuthService {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
// Load from localStorage if available
|
// Load from localStorage if available
|
||||||
const savedUser = localStorage.getItem('mock_user');
|
const savedUser = localStorage.getItem("mock_user");
|
||||||
const savedProfile = localStorage.getItem('mock_profile');
|
const savedProfile = localStorage.getItem("mock_profile");
|
||||||
|
|
||||||
if (savedUser) {
|
if (savedUser) {
|
||||||
this.currentUser = JSON.parse(savedUser);
|
this.currentUser = JSON.parse(savedUser);
|
||||||
if (this.currentUser) {
|
if (this.currentUser) {
|
||||||
this.currentSession = {
|
this.currentSession = {
|
||||||
user: this.currentUser,
|
user: this.currentUser,
|
||||||
access_token: 'mock_token_' + Date.now()
|
access_token: "mock_token_" + Date.now(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (savedProfile) {
|
if (savedProfile) {
|
||||||
const profile = JSON.parse(savedProfile);
|
const profile = JSON.parse(savedProfile);
|
||||||
this.profiles.set(profile.id, profile);
|
this.profiles.set(profile.id, profile);
|
||||||
|
|
@ -54,33 +54,33 @@ class MockAuthService {
|
||||||
async signInWithPassword(email: string, password: string) {
|
async signInWithPassword(email: string, password: string) {
|
||||||
// Mock validation - accept any email/password for demo
|
// Mock validation - accept any email/password for demo
|
||||||
if (!email || !password) {
|
if (!email || !password) {
|
||||||
throw new Error('Email and password are required');
|
throw new Error("Email and password are required");
|
||||||
}
|
}
|
||||||
|
|
||||||
const user: MockUser = {
|
const user: MockUser = {
|
||||||
id: 'mock_user_' + email.replace(/[^a-z0-9]/gi, '_'),
|
id: "mock_user_" + email.replace(/[^a-z0-9]/gi, "_"),
|
||||||
email,
|
email,
|
||||||
created_at: new Date().toISOString()
|
created_at: new Date().toISOString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
this.currentUser = user;
|
this.currentUser = user;
|
||||||
this.currentSession = {
|
this.currentSession = {
|
||||||
user,
|
user,
|
||||||
access_token: 'mock_token_' + Date.now()
|
access_token: "mock_token_" + Date.now(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Save to localStorage
|
// Save to localStorage
|
||||||
localStorage.setItem('mock_user', JSON.stringify(user));
|
localStorage.setItem("mock_user", JSON.stringify(user));
|
||||||
|
|
||||||
// Notify auth state change
|
// Notify auth state change
|
||||||
setTimeout(() => this.notifyAuthChange('SIGNED_IN'), 50);
|
setTimeout(() => this.notifyAuthChange("SIGNED_IN"), 50);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: {
|
data: {
|
||||||
user,
|
user,
|
||||||
session: this.currentSession
|
session: this.currentSession,
|
||||||
},
|
},
|
||||||
error: null
|
error: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,14 +95,14 @@ class MockAuthService {
|
||||||
this.currentUser = user;
|
this.currentUser = user;
|
||||||
this.currentSession = {
|
this.currentSession = {
|
||||||
user,
|
user,
|
||||||
access_token: 'mock_oauth_token_' + Date.now(),
|
access_token: "mock_oauth_token_" + Date.now(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Save to localStorage
|
// Save to localStorage
|
||||||
localStorage.setItem('mock_user', JSON.stringify(user));
|
localStorage.setItem("mock_user", JSON.stringify(user));
|
||||||
|
|
||||||
// Notify auth state change after a short delay to simulate redirect
|
// Notify auth state change after a short delay to simulate redirect
|
||||||
setTimeout(() => this.notifyAuthChange('SIGNED_IN'), 50);
|
setTimeout(() => this.notifyAuthChange("SIGNED_IN"), 50);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: { user, session: this.currentSession },
|
data: { user, session: this.currentSession },
|
||||||
|
|
@ -113,11 +113,11 @@ class MockAuthService {
|
||||||
async signOut() {
|
async signOut() {
|
||||||
this.currentUser = null;
|
this.currentUser = null;
|
||||||
this.currentSession = null;
|
this.currentSession = null;
|
||||||
localStorage.removeItem('mock_user');
|
localStorage.removeItem("mock_user");
|
||||||
localStorage.removeItem('mock_profile');
|
localStorage.removeItem("mock_profile");
|
||||||
|
|
||||||
// Notify auth state change
|
// Notify auth state change
|
||||||
setTimeout(() => this.notifyAuthChange('SIGNED_OUT'), 50);
|
setTimeout(() => this.notifyAuthChange("SIGNED_OUT"), 50);
|
||||||
|
|
||||||
return { error: null };
|
return { error: null };
|
||||||
}
|
}
|
||||||
|
|
@ -125,14 +125,14 @@ class MockAuthService {
|
||||||
async getUser() {
|
async getUser() {
|
||||||
return {
|
return {
|
||||||
data: { user: this.currentUser },
|
data: { user: this.currentUser },
|
||||||
error: null
|
error: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSession() {
|
async getSession() {
|
||||||
return {
|
return {
|
||||||
data: { session: this.currentSession },
|
data: { session: this.currentSession },
|
||||||
error: null
|
error: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -141,48 +141,54 @@ class MockAuthService {
|
||||||
return this.profiles.get(userId) || null;
|
return this.profiles.get(userId) || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateProfile(userId: string, updates: Partial<MockProfile>): Promise<MockProfile> {
|
async updateProfile(
|
||||||
|
userId: string,
|
||||||
|
updates: Partial<MockProfile>,
|
||||||
|
): Promise<MockProfile> {
|
||||||
let profile = this.profiles.get(userId);
|
let profile = this.profiles.get(userId);
|
||||||
|
|
||||||
if (!profile) {
|
if (!profile) {
|
||||||
// Create new profile
|
// Create new profile
|
||||||
profile = {
|
profile = {
|
||||||
id: userId,
|
id: userId,
|
||||||
username: updates.username || this.currentUser?.email?.split('@')[0] || 'user',
|
username:
|
||||||
email: this.currentUser?.email || '',
|
updates.username || this.currentUser?.email?.split("@")[0] || "user",
|
||||||
role: 'member',
|
email: this.currentUser?.email || "",
|
||||||
|
role: "member",
|
||||||
onboarded: true,
|
onboarded: true,
|
||||||
level: 1,
|
level: 1,
|
||||||
total_xp: 0,
|
total_xp: 0,
|
||||||
created_at: new Date().toISOString(),
|
created_at: new Date().toISOString(),
|
||||||
updated_at: new Date().toISOString(),
|
updated_at: new Date().toISOString(),
|
||||||
...updates
|
...updates,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
// Update existing
|
// Update existing
|
||||||
profile = {
|
profile = {
|
||||||
...profile,
|
...profile,
|
||||||
...updates,
|
...updates,
|
||||||
updated_at: new Date().toISOString()
|
updated_at: new Date().toISOString(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
this.profiles.set(userId, profile);
|
this.profiles.set(userId, profile);
|
||||||
localStorage.setItem('mock_profile', JSON.stringify(profile));
|
localStorage.setItem("mock_profile", JSON.stringify(profile));
|
||||||
|
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
onAuthStateChange(callback: (event: string, session: MockSession | null) => void) {
|
onAuthStateChange(
|
||||||
|
callback: (event: string, session: MockSession | null) => void,
|
||||||
|
) {
|
||||||
// Store callback for later use
|
// Store callback for later use
|
||||||
this.authCallback = callback;
|
this.authCallback = callback;
|
||||||
|
|
||||||
// Immediately call with current state
|
// Immediately call with current state
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (this.currentSession) {
|
if (this.currentSession) {
|
||||||
callback('SIGNED_IN', this.currentSession);
|
callback("SIGNED_IN", this.currentSession);
|
||||||
} else {
|
} else {
|
||||||
callback('SIGNED_OUT', null);
|
callback("SIGNED_OUT", null);
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
|
|
@ -192,13 +198,15 @@ class MockAuthService {
|
||||||
subscription: {
|
subscription: {
|
||||||
unsubscribe: () => {
|
unsubscribe: () => {
|
||||||
this.authCallback = null;
|
this.authCallback = null;
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private authCallback: ((event: string, session: MockSession | null) => void) | null = null;
|
private authCallback:
|
||||||
|
| ((event: string, session: MockSession | null) => void)
|
||||||
|
| null = null;
|
||||||
|
|
||||||
private notifyAuthChange(event: string) {
|
private notifyAuthChange(event: string) {
|
||||||
if (this.authCallback) {
|
if (this.authCallback) {
|
||||||
|
|
|
||||||
|
|
@ -105,11 +105,19 @@ export const supabase = new Proxy(supabaseClient || {}, {
|
||||||
// OAuth sign-in (GitHub/Google). Falls back to mock in development.
|
// OAuth sign-in (GitHub/Google). Falls back to mock in development.
|
||||||
signInWithOAuth: async (opts: any) => {
|
signInWithOAuth: async (opts: any) => {
|
||||||
const provider = opts?.provider;
|
const provider = opts?.provider;
|
||||||
if (isSupabaseConfigured && target && target.auth && typeof target.auth.signInWithOAuth === 'function') {
|
if (
|
||||||
|
isSupabaseConfigured &&
|
||||||
|
target &&
|
||||||
|
target.auth &&
|
||||||
|
typeof target.auth.signInWithOAuth === "function"
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
return await target.auth.signInWithOAuth(opts);
|
return await target.auth.signInWithOAuth(opts);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.warn('Supabase signInWithOAuth failed:', error?.message || error);
|
console.warn(
|
||||||
|
"Supabase signInWithOAuth failed:",
|
||||||
|
error?.message || error,
|
||||||
|
);
|
||||||
try {
|
try {
|
||||||
return await mockAuth.signInWithOAuth(provider);
|
return await mockAuth.signInWithOAuth(provider);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
@ -157,7 +165,9 @@ export const supabase = new Proxy(supabaseClient || {}, {
|
||||||
try {
|
try {
|
||||||
realSub = target.auth.onAuthStateChange(callback);
|
realSub = target.auth.onAuthStateChange(callback);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn("Supabase onAuthStateChange failed, will use mock too");
|
console.warn(
|
||||||
|
"Supabase onAuthStateChange failed, will use mock too",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Always subscribe to mock as a safety net in case we fall back during auth
|
// Always subscribe to mock as a safety net in case we fall back during auth
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue