feat: add loginWithTokens method to auth context for OAuth flow
This commit is contained in:
@@ -10,6 +10,7 @@ type AuthContextType = {
|
||||
register: (email: string, password: string, name: string) => Promise<void>;
|
||||
logout: () => void;
|
||||
updateUser: (updates: Partial<User>) => void;
|
||||
loginWithTokens: (accessToken: string, refreshToken: string) => Promise<void>;
|
||||
};
|
||||
|
||||
const AuthContext = createContext<AuthContextType | null>(null);
|
||||
@@ -53,8 +54,14 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
setUser(prev => prev ? { ...prev, ...updates } : null);
|
||||
};
|
||||
|
||||
const loginWithTokens = async (access: string, refresh: string) => {
|
||||
setTokens(access, refresh);
|
||||
const user = await apiFetch<User>('/auth/me');
|
||||
setUser(user);
|
||||
};
|
||||
|
||||
return (
|
||||
<AuthContext.Provider value={{ user, loading, login, register, logout, updateUser }}>
|
||||
<AuthContext.Provider value={{ user, loading, login, register, logout, updateUser, loginWithTokens }}>
|
||||
{children}
|
||||
</AuthContext.Provider>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user