Merge branch 'login-auth' of https://github.com/logspace-ai/langflow into login-auth
This commit is contained in:
commit
96330d6064
12 changed files with 79 additions and 39 deletions
|
|
@ -14,7 +14,7 @@ import { alertContext } from "./contexts/alertContext";
|
||||||
import { AuthContext } from "./contexts/authContext";
|
import { AuthContext } from "./contexts/authContext";
|
||||||
import { locationContext } from "./contexts/locationContext";
|
import { locationContext } from "./contexts/locationContext";
|
||||||
import { TabsContext } from "./contexts/tabsContext";
|
import { TabsContext } from "./contexts/tabsContext";
|
||||||
import { autoLogin, getLoggedUser, onLogin } from "./controllers/API";
|
import { autoLogin, getLoggedUser } from "./controllers/API";
|
||||||
import Router from "./routes";
|
import Router from "./routes";
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
|
|
@ -37,7 +37,7 @@ export default function App() {
|
||||||
successData,
|
successData,
|
||||||
successOpen,
|
successOpen,
|
||||||
setSuccessOpen,
|
setSuccessOpen,
|
||||||
setErrorData
|
setErrorData,
|
||||||
} = useContext(alertContext);
|
} = useContext(alertContext);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
|
@ -131,7 +131,8 @@ export default function App() {
|
||||||
};
|
};
|
||||||
|
|
||||||
//this function is to get the user logged in when the page is refreshed
|
//this function is to get the user logged in when the page is refreshed
|
||||||
const { setUserData, getAuthentication, login, setAutoLogin } = useContext(AuthContext);
|
const { setUserData, getAuthentication, login, setAutoLogin } =
|
||||||
|
useContext(AuthContext);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
@ -154,7 +155,6 @@ export default function App() {
|
||||||
}, 500);
|
}, 500);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
//need parent component with width and height
|
//need parent component with width and height
|
||||||
<div className="flex h-full flex-col">
|
<div className="flex h-full flex-col">
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,9 @@ export default function PaginatorComponent({
|
||||||
}: PaginatorComponentType) {
|
}: PaginatorComponentType) {
|
||||||
const [size, setPageSize] = useState(pageSize);
|
const [size, setPageSize] = useState(pageSize);
|
||||||
const [index, setPageIndex] = useState(pageIndex);
|
const [index, setPageIndex] = useState(pageIndex);
|
||||||
const [maxIndex, setMaxPageIndex] = useState(Math.ceil(totalRowsCount/pageSize));
|
const [maxIndex, setMaxPageIndex] = useState(
|
||||||
|
Math.ceil(totalRowsCount / pageSize)
|
||||||
|
);
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -32,7 +34,7 @@ export default function PaginatorComponent({
|
||||||
<Select
|
<Select
|
||||||
onValueChange={(pageSize: string) => {
|
onValueChange={(pageSize: string) => {
|
||||||
setPageSize(Number(pageSize));
|
setPageSize(Number(pageSize));
|
||||||
setMaxPageIndex(Math.ceil(totalRowsCount/Number(pageSize)))
|
setMaxPageIndex(Math.ceil(totalRowsCount / Number(pageSize)));
|
||||||
paginate(Number(pageSize), 0);
|
paginate(Number(pageSize), 0);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
@ -70,7 +72,7 @@ export default function PaginatorComponent({
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
const pgIndex = size - index;
|
const pgIndex = size - index;
|
||||||
setCurrentPage(currentPage-1);
|
setCurrentPage(currentPage - 1);
|
||||||
setPageIndex(pgIndex);
|
setPageIndex(pgIndex);
|
||||||
paginate(size, pgIndex);
|
paginate(size, pgIndex);
|
||||||
}
|
}
|
||||||
|
|
@ -86,7 +88,7 @@ export default function PaginatorComponent({
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const pgIndex = size + index;
|
const pgIndex = size + index;
|
||||||
setPageIndex(pgIndex);
|
setPageIndex(pgIndex);
|
||||||
setCurrentPage(currentPage+1);
|
setCurrentPage(currentPage + 1);
|
||||||
paginate(size, pgIndex);
|
paginate(size, pgIndex);
|
||||||
}}
|
}}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
|
@ -100,7 +102,7 @@ export default function PaginatorComponent({
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="hidden h-8 w-8 p-0 lg:flex"
|
className="hidden h-8 w-8 p-0 lg:flex"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setPageIndex(maxIndex-1);
|
setPageIndex(maxIndex - 1);
|
||||||
setCurrentPage(maxIndex);
|
setCurrentPage(maxIndex);
|
||||||
paginate(size, size);
|
paginate(size, size);
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { AuthContext } from "../../contexts/authContext";
|
||||||
export const ProtectedLoginRoute = ({ children }) => {
|
export const ProtectedLoginRoute = ({ children }) => {
|
||||||
const { getAuthentication, autoLogin } = useContext(AuthContext);
|
const { getAuthentication, autoLogin } = useContext(AuthContext);
|
||||||
|
|
||||||
if(autoLogin === true){
|
if (autoLogin === true) {
|
||||||
window.location.replace("/");
|
window.location.replace("/");
|
||||||
return <Navigate to="/" replace />;
|
return <Navigate to="/" replace />;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,11 @@ import { alertContext } from "../../contexts/alertContext";
|
||||||
import { AuthContext } from "../../contexts/authContext";
|
import { AuthContext } from "../../contexts/authContext";
|
||||||
import { darkContext } from "../../contexts/darkContext";
|
import { darkContext } from "../../contexts/darkContext";
|
||||||
import { TabsContext } from "../../contexts/tabsContext";
|
import { TabsContext } from "../../contexts/tabsContext";
|
||||||
import { getLoggedUser, getRepoStars } from "../../controllers/API";
|
import { getRepoStars } from "../../controllers/API";
|
||||||
import IconComponent from "../genericIconComponent";
|
import IconComponent from "../genericIconComponent";
|
||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
import { Separator } from "../ui/separator";
|
import { Separator } from "../ui/separator";
|
||||||
import MenuBar from "./components/menuBar";
|
import MenuBar from "./components/menuBar";
|
||||||
import { Users } from "../../types/api";
|
|
||||||
|
|
||||||
export default function Header() {
|
export default function Header() {
|
||||||
const { flows, tabId } = useContext(TabsContext);
|
const { flows, tabId } = useContext(TabsContext);
|
||||||
|
|
@ -53,17 +52,13 @@ export default function Header() {
|
||||||
Sign out
|
Sign out
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{isAdmin && (
|
{isAdmin && (
|
||||||
<Button
|
<Button variant="outline" onClick={() => navigate("/admin")}>
|
||||||
variant="outline"
|
|
||||||
onClick={() => navigate("/admin")}
|
|
||||||
>
|
|
||||||
Admin page
|
Admin page
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
||||||
{flows.findIndex((f) => tabId === f.id) !== -1 && tabId !== "" && (
|
{flows.findIndex((f) => tabId === f.id) !== -1 && tabId !== "" && (
|
||||||
<MenuBar flows={flows} tabId={tabId} />
|
<MenuBar flows={flows} tabId={tabId} />
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -614,3 +614,6 @@ export function tabsArray(codes: string[], method: number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const BASE_URL_API = "http://localhost:7860/";
|
export const BASE_URL_API = "http://localhost:7860/";
|
||||||
|
|
||||||
|
export const SIGN_UP_SUCCESS =
|
||||||
|
"Congratulations on signing up! Your account is currently awaiting activation by our admin team.";
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import { createContext, useEffect, useState } from "react";
|
import { createContext, useEffect, useState } from "react";
|
||||||
import Cookies from "universal-cookie";
|
import Cookies from "universal-cookie";
|
||||||
|
import { getLoggedUser } from "../controllers/API";
|
||||||
import { Users } from "../types/api";
|
import { Users } from "../types/api";
|
||||||
import { AuthContextType } from "../types/contexts/auth";
|
import { AuthContextType } from "../types/contexts/auth";
|
||||||
import { getLoggedUser } from "../controllers/API";
|
|
||||||
|
|
||||||
const initialValue: AuthContextType = {
|
const initialValue: AuthContextType = {
|
||||||
isAdmin: false,
|
isAdmin: false,
|
||||||
|
|
@ -38,15 +38,15 @@ export function AuthProvider({ children }): React.ReactElement {
|
||||||
setAccessToken(storedAccessToken);
|
setAccessToken(storedAccessToken);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
getLoggedUser().then((user) => {
|
getLoggedUser().then((user) => {
|
||||||
const isSuperUser = user.is_superuser
|
const isSuperUser = user.is_superuser;
|
||||||
setIsAdmin(isSuperUser);
|
setIsAdmin(isSuperUser);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [accessToken, isAdmin])
|
}, [accessToken, isAdmin]);
|
||||||
|
|
||||||
function getAuthentication() {
|
function getAuthentication() {
|
||||||
const storedRefreshToken = cookies.get("refresh_token");
|
const storedRefreshToken = cookies.get("refresh_token");
|
||||||
|
|
@ -85,7 +85,9 @@ export function AuthProvider({ children }): React.ReactElement {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
login(data.accessToken, refreshToken);
|
login(data.accessToken, refreshToken);
|
||||||
getLoggedUser().then((user) => { console.log('oi')});
|
getLoggedUser().then((user) => {
|
||||||
|
console.log("oi");
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
logout();
|
logout();
|
||||||
}
|
}
|
||||||
|
|
@ -111,7 +113,7 @@ export function AuthProvider({ children }): React.ReactElement {
|
||||||
getAuthentication,
|
getAuthentication,
|
||||||
authenticationErrorCount: 0,
|
authenticationErrorCount: 0,
|
||||||
setAutoLogin,
|
setAutoLogin,
|
||||||
autoLogin
|
autoLogin,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|
|
||||||
|
|
@ -79,11 +79,8 @@ function ApiInterceptor() {
|
||||||
) ||
|
) ||
|
||||||
config?.url?.includes(
|
config?.url?.includes(
|
||||||
"https://api.github.com/repos/logspace-ai/langflow"
|
"https://api.github.com/repos/logspace-ai/langflow"
|
||||||
)
|
) ||
|
||||||
||
|
config?.url?.includes("auto_login")
|
||||||
config?.url?.includes(
|
|
||||||
"auto_login"
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
delete config.headers["Authorization"];
|
delete config.headers["Authorization"];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -380,9 +380,7 @@ export async function onLogin(user: LoginType) {
|
||||||
|
|
||||||
export async function autoLogin() {
|
export async function autoLogin() {
|
||||||
try {
|
try {
|
||||||
const response = await api.get(
|
const response = await api.get(`${BASE_URL_API}auto_login`);
|
||||||
`${BASE_URL_API}auto_login`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
const data = response.data;
|
const data = response.data;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import * as Form from "@radix-ui/react-form";
|
import * as Form from "@radix-ui/react-form";
|
||||||
import { useContext, useEffect, useState } from "react";
|
import { useContext, useState } from "react";
|
||||||
import { Link, useNavigate } from "react-router-dom";
|
import { Link, useNavigate } from "react-router-dom";
|
||||||
import InputComponent from "../../components/inputComponent";
|
import InputComponent from "../../components/inputComponent";
|
||||||
import { Button } from "../../components/ui/button";
|
import { Button } from "../../components/ui/button";
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,17 @@
|
||||||
import * as Form from "@radix-ui/react-form";
|
import * as Form from "@radix-ui/react-form";
|
||||||
import { FormEvent, useState } from "react";
|
import { FormEvent, useContext, useState } from "react";
|
||||||
import { Link } from "react-router-dom";
|
import { Link, useNavigate } from "react-router-dom";
|
||||||
import InputComponent from "../../components/inputComponent";
|
import InputComponent from "../../components/inputComponent";
|
||||||
import { Button } from "../../components/ui/button";
|
import { Button } from "../../components/ui/button";
|
||||||
import { Input } from "../../components/ui/input";
|
import { Input } from "../../components/ui/input";
|
||||||
import { CONTROL_INPUT_STATE } from "../../constants/constants";
|
|
||||||
import {
|
import {
|
||||||
|
CONTROL_INPUT_STATE,
|
||||||
|
SIGN_UP_SUCCESS,
|
||||||
|
} from "../../constants/constants";
|
||||||
|
import { alertContext } from "../../contexts/alertContext";
|
||||||
|
import { addUser } from "../../controllers/API";
|
||||||
|
import {
|
||||||
|
UserInputType,
|
||||||
inputHandlerEventType,
|
inputHandlerEventType,
|
||||||
signUpInputStateType,
|
signUpInputStateType,
|
||||||
} from "../../types/components";
|
} from "../../types/components";
|
||||||
|
|
@ -15,12 +21,42 @@ export default function SignUp(): JSX.Element {
|
||||||
useState<signUpInputStateType>(CONTROL_INPUT_STATE);
|
useState<signUpInputStateType>(CONTROL_INPUT_STATE);
|
||||||
|
|
||||||
const { password, cnfPassword, username } = inputState;
|
const { password, cnfPassword, username } = inputState;
|
||||||
|
const { setErrorData, setSuccessData } = useContext(alertContext);
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
function handleInput({
|
function handleInput({
|
||||||
target: { name, value },
|
target: { name, value },
|
||||||
}: inputHandlerEventType): void {
|
}: inputHandlerEventType): void {
|
||||||
setInputState((prev) => ({ ...prev, [name]: value }));
|
setInputState((prev) => ({ ...prev, [name]: value }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleSignup(): void {
|
||||||
|
const { username, password } = inputState;
|
||||||
|
const newUser: UserInputType = {
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
};
|
||||||
|
addUser(newUser)
|
||||||
|
.then((user) => {
|
||||||
|
setSuccessData({
|
||||||
|
title: SIGN_UP_SUCCESS,
|
||||||
|
});
|
||||||
|
navigate("/login");
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
const {
|
||||||
|
response: {
|
||||||
|
data: { detail },
|
||||||
|
},
|
||||||
|
} = error;
|
||||||
|
setErrorData({
|
||||||
|
title: "Error signing up",
|
||||||
|
list: [detail[0].msg],
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form.Root
|
<Form.Root
|
||||||
onSubmit={(event: FormEvent<HTMLFormElement>) => {
|
onSubmit={(event: FormEvent<HTMLFormElement>) => {
|
||||||
|
|
@ -120,7 +156,14 @@ export default function SignUp(): JSX.Element {
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<Form.Submit asChild>
|
<Form.Submit asChild>
|
||||||
<Button className="mr-3 mt-6 w-full">Sign up</Button>
|
<Button
|
||||||
|
className="mr-3 mt-6 w-full"
|
||||||
|
onClick={() => {
|
||||||
|
handleSignup();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Sign up
|
||||||
|
</Button>
|
||||||
</Form.Submit>
|
</Form.Submit>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
|
|
|
||||||
|
|
@ -14,5 +14,5 @@ export type AuthContextType = {
|
||||||
getAuthentication: () => boolean;
|
getAuthentication: () => boolean;
|
||||||
authenticationErrorCount: number;
|
authenticationErrorCount: number;
|
||||||
autoLogin: boolean;
|
autoLogin: boolean;
|
||||||
setAutoLogin: (autoLogin: boolean) => void
|
setAutoLogin: (autoLogin: boolean) => void;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ import {
|
||||||
HelpCircle,
|
HelpCircle,
|
||||||
Home,
|
Home,
|
||||||
Info,
|
Info,
|
||||||
|
Key,
|
||||||
Laptop2,
|
Laptop2,
|
||||||
Layers,
|
Layers,
|
||||||
Lightbulb,
|
Lightbulb,
|
||||||
|
|
@ -72,7 +73,6 @@ import {
|
||||||
X,
|
X,
|
||||||
XCircle,
|
XCircle,
|
||||||
Zap,
|
Zap,
|
||||||
Key
|
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { FaApple, FaGithub } from "react-icons/fa";
|
import { FaApple, FaGithub } from "react-icons/fa";
|
||||||
import { AirbyteIcon } from "../icons/Airbyte";
|
import { AirbyteIcon } from "../icons/Airbyte";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue