Merge branch 'login' of https://github.com/logspace-ai/langflow into login
This commit is contained in:
commit
38eb1a2d79
8 changed files with 25 additions and 17 deletions
|
|
@ -17,7 +17,8 @@ export default function Header(): JSX.Element {
|
||||||
const { dark, setDark } = useContext(darkContext);
|
const { dark, setDark } = useContext(darkContext);
|
||||||
const { notificationCenter } = useContext(alertContext);
|
const { notificationCenter } = useContext(alertContext);
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const { logout, autoLogin, isAdmin, stars } = useContext(AuthContext);
|
const { logout, autoLogin, isAdmin } = useContext(AuthContext);
|
||||||
|
const { stars } = useContext(darkContext);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,6 @@ const initialValue: AuthContextType = {
|
||||||
authenticationErrorCount: 0,
|
authenticationErrorCount: 0,
|
||||||
autoLogin: false,
|
autoLogin: false,
|
||||||
setAutoLogin: () => {},
|
setAutoLogin: () => {},
|
||||||
stars: 0,
|
|
||||||
setStars: (stars) => 0,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const AuthContext = createContext<AuthContextType>(initialValue);
|
export const AuthContext = createContext<AuthContextType>(initialValue);
|
||||||
|
|
@ -32,7 +30,6 @@ export function AuthProvider({ children }): React.ReactElement {
|
||||||
const [isAdmin, setIsAdmin] = useState<boolean>(false);
|
const [isAdmin, setIsAdmin] = useState<boolean>(false);
|
||||||
const [userData, setUserData] = useState<Users | null>(null);
|
const [userData, setUserData] = useState<Users | null>(null);
|
||||||
const [autoLogin, setAutoLogin] = useState<boolean>(false);
|
const [autoLogin, setAutoLogin] = useState<boolean>(false);
|
||||||
const [stars, setStars] = useState<number>(0);
|
|
||||||
const cookies = new Cookies();
|
const cookies = new Cookies();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -40,11 +37,6 @@ export function AuthProvider({ children }): React.ReactElement {
|
||||||
if (storedAccessToken) {
|
if (storedAccessToken) {
|
||||||
setAccessToken(storedAccessToken);
|
setAccessToken(storedAccessToken);
|
||||||
}
|
}
|
||||||
async function fetchStars() {
|
|
||||||
const starsCount = await getRepoStars("logspace-ai", "langflow");
|
|
||||||
setStars(starsCount);
|
|
||||||
}
|
|
||||||
fetchStars();
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -100,8 +92,6 @@ export function AuthProvider({ children }): React.ReactElement {
|
||||||
// !! to convert string to boolean
|
// !! to convert string to boolean
|
||||||
<AuthContext.Provider
|
<AuthContext.Provider
|
||||||
value={{
|
value={{
|
||||||
stars,
|
|
||||||
setStars,
|
|
||||||
isAdmin,
|
isAdmin,
|
||||||
setIsAdmin,
|
setIsAdmin,
|
||||||
isAuthenticated: !!accessToken,
|
isAuthenticated: !!accessToken,
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
import { createContext, useEffect, useState } from "react";
|
import { createContext, useEffect, useState } from "react";
|
||||||
import { darkContextType } from "../types/typesContext";
|
import { darkContextType } from "../types/typesContext";
|
||||||
|
import { getRepoStars } from "../controllers/API";
|
||||||
|
|
||||||
const initialValue = {
|
const initialValue = {
|
||||||
dark: {},
|
dark: {},
|
||||||
setDark: () => {},
|
setDark: () => {},
|
||||||
|
stars: 0,
|
||||||
|
setStars: (stars) => 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const darkContext = createContext<darkContextType>(initialValue);
|
export const darkContext = createContext<darkContextType>(initialValue);
|
||||||
|
|
@ -12,6 +15,16 @@ export function DarkProvider({ children }) {
|
||||||
const [dark, setDark] = useState(
|
const [dark, setDark] = useState(
|
||||||
JSON.parse(window.localStorage.getItem("isDark")!) ?? false
|
JSON.parse(window.localStorage.getItem("isDark")!) ?? false
|
||||||
);
|
);
|
||||||
|
const [stars, setStars] = useState<number>(0);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function fetchStars() {
|
||||||
|
const starsCount = await getRepoStars("logspace-ai", "langflow");
|
||||||
|
setStars(starsCount);
|
||||||
|
}
|
||||||
|
fetchStars();
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (dark) {
|
if (dark) {
|
||||||
document.getElementById("body")!.classList.add("dark");
|
document.getElementById("body")!.classList.add("dark");
|
||||||
|
|
@ -20,9 +33,12 @@ export function DarkProvider({ children }) {
|
||||||
}
|
}
|
||||||
window.localStorage.setItem("isDark", dark.toString());
|
window.localStorage.setItem("isDark", dark.toString());
|
||||||
}, [dark]);
|
}, [dark]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<darkContext.Provider
|
<darkContext.Provider
|
||||||
value={{
|
value={{
|
||||||
|
setStars,
|
||||||
|
stars,
|
||||||
dark,
|
dark,
|
||||||
setDark,
|
setDark,
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,14 @@ import { LocationProvider } from "./locationContext";
|
||||||
import { TabsProvider } from "./tabsContext";
|
import { TabsProvider } from "./tabsContext";
|
||||||
import { TypesProvider } from "./typesContext";
|
import { TypesProvider } from "./typesContext";
|
||||||
import { UndoRedoProvider } from "./undoRedoContext";
|
import { UndoRedoProvider } from "./undoRedoContext";
|
||||||
|
import { BrowserRouter } from "react-router-dom";
|
||||||
|
import { ApiInterceptor } from "../controllers/API/api";
|
||||||
|
|
||||||
export default function ContextWrapper({ children }: { children: ReactNode }) {
|
export default function ContextWrapper({ children }: { children: ReactNode }) {
|
||||||
//element to wrap all context
|
//element to wrap all context
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
<BrowserRouter>
|
||||||
<AuthProvider>
|
<AuthProvider>
|
||||||
<TooltipProvider>
|
<TooltipProvider>
|
||||||
<ReactFlowProvider>
|
<ReactFlowProvider>
|
||||||
|
|
@ -21,6 +24,7 @@ export default function ContextWrapper({ children }: { children: ReactNode }) {
|
||||||
<TypesProvider>
|
<TypesProvider>
|
||||||
<LocationProvider>
|
<LocationProvider>
|
||||||
<AlertProvider>
|
<AlertProvider>
|
||||||
|
<ApiInterceptor />
|
||||||
<SSEProvider>
|
<SSEProvider>
|
||||||
<TabsProvider>
|
<TabsProvider>
|
||||||
<UndoRedoProvider>{children}</UndoRedoProvider>
|
<UndoRedoProvider>{children}</UndoRedoProvider>
|
||||||
|
|
@ -33,6 +37,7 @@ export default function ContextWrapper({ children }: { children: ReactNode }) {
|
||||||
</ReactFlowProvider>
|
</ReactFlowProvider>
|
||||||
</TooltipProvider>
|
</TooltipProvider>
|
||||||
</AuthProvider>
|
</AuthProvider>
|
||||||
|
</BrowserRouter>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ function ApiInterceptor() {
|
||||||
async (error: AxiosError) => {
|
async (error: AxiosError) => {
|
||||||
if (error.response?.status === 401) {
|
if (error.response?.status === 401) {
|
||||||
const refreshToken = cookies.get("refresh_token");
|
const refreshToken = cookies.get("refresh_token");
|
||||||
|
|
||||||
if (refreshToken) {
|
if (refreshToken) {
|
||||||
authenticationErrorCount = authenticationErrorCount + 1;
|
authenticationErrorCount = authenticationErrorCount + 1;
|
||||||
if (authenticationErrorCount > 3) {
|
if (authenticationErrorCount > 3) {
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,7 @@ const root = ReactDOM.createRoot(
|
||||||
);
|
);
|
||||||
root.render(
|
root.render(
|
||||||
<ContextWrapper>
|
<ContextWrapper>
|
||||||
<BrowserRouter>
|
|
||||||
<App />
|
<App />
|
||||||
<ApiInterceptor />
|
|
||||||
</BrowserRouter>
|
|
||||||
</ContextWrapper>
|
</ContextWrapper>
|
||||||
);
|
);
|
||||||
reportWebVitals();
|
reportWebVitals();
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,4 @@ export type AuthContextType = {
|
||||||
authenticationErrorCount: number;
|
authenticationErrorCount: number;
|
||||||
autoLogin: boolean;
|
autoLogin: boolean;
|
||||||
setAutoLogin: (autoLogin: boolean) => void;
|
setAutoLogin: (autoLogin: boolean) => void;
|
||||||
stars: number;
|
|
||||||
setStars: (stars: number) => void;
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,8 @@ export type alertContextType = {
|
||||||
export type darkContextType = {
|
export type darkContextType = {
|
||||||
dark: {};
|
dark: {};
|
||||||
setDark: (newState: {}) => void;
|
setDark: (newState: {}) => void;
|
||||||
|
stars: number;
|
||||||
|
setStars: (stars: number) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type locationContextType = {
|
export type locationContextType = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue