mirror of
https://github.com/patdelphi/suanming.git
synced 2026-03-07 00:53:11 +08:00
feat: 保存当前Supabase版本,准备进行本地化改造
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import React, { createContext, useContext, useEffect, useState, ReactNode } from 'react';
|
||||
import { User } from '../lib/localApi';
|
||||
import { User } from '@supabase/supabase-js';
|
||||
import { supabase } from '../lib/supabase';
|
||||
|
||||
interface AuthContextType {
|
||||
@@ -25,26 +25,19 @@ export function AuthProvider({ children }: AuthProviderProps) {
|
||||
async function loadUser() {
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await supabase.auth.getUser();
|
||||
if (response.data?.user) {
|
||||
setUser(response.data.user);
|
||||
} else {
|
||||
setUser(null);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载用户信息失败:', error);
|
||||
setUser(null);
|
||||
const { data: { user } } = await supabase.auth.getUser();
|
||||
setUser(user);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
loadUser();
|
||||
|
||||
// Set up auth listener - 本地API版本
|
||||
// Set up auth listener - KEEP SIMPLE, avoid any async operations in callback
|
||||
const { data: { subscription } } = supabase.auth.onAuthStateChange(
|
||||
(_event, session) => {
|
||||
// NEVER use any async operations in callback
|
||||
setUser(session?.user || null);
|
||||
setLoading(false);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -53,25 +46,18 @@ export function AuthProvider({ children }: AuthProviderProps) {
|
||||
|
||||
// Auth methods
|
||||
async function signIn(email: string, password: string) {
|
||||
const response = await supabase.auth.signInWithPassword({ email, password });
|
||||
if (response.data?.user) {
|
||||
setUser(response.data.user);
|
||||
}
|
||||
return response;
|
||||
return await supabase.auth.signInWithPassword({ email, password });
|
||||
}
|
||||
|
||||
async function signUp(email: string, password: string) {
|
||||
const response = await supabase.auth.signUp({ email, password });
|
||||
if (response.data?.user) {
|
||||
setUser(response.data.user);
|
||||
}
|
||||
return response;
|
||||
return await supabase.auth.signUp({
|
||||
email,
|
||||
password,
|
||||
});
|
||||
}
|
||||
|
||||
async function signOut() {
|
||||
const response = await supabase.auth.signOut();
|
||||
setUser(null);
|
||||
return response;
|
||||
return await supabase.auth.signOut();
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user