Merge branch 'login' of https://github.com/logspace-ai/langflow into login
This commit is contained in:
commit
6867811626
7 changed files with 25 additions and 17 deletions
|
|
@ -191,7 +191,7 @@ class ChatManager(Service):
|
||||||
json_payload = await websocket.receive_json()
|
json_payload = await websocket.receive_json()
|
||||||
try:
|
try:
|
||||||
payload = orjson.loads(json_payload)
|
payload = orjson.loads(json_payload)
|
||||||
except TypeError:
|
except Exception:
|
||||||
payload = json_payload
|
payload = json_payload
|
||||||
if "clear_history" in payload:
|
if "clear_history" in payload:
|
||||||
self.chat_history.history[client_id] = []
|
self.chat_history.history[client_id] = []
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,9 @@ class ApiKeyBase(SQLModelSerializable):
|
||||||
|
|
||||||
class ApiKey(ApiKeyBase, table=True):
|
class ApiKey(ApiKeyBase, table=True):
|
||||||
id: UUID = Field(default_factory=uuid4, primary_key=True, unique=True)
|
id: UUID = Field(default_factory=uuid4, primary_key=True, unique=True)
|
||||||
|
|
||||||
api_key: str = Field(index=True, unique=True)
|
api_key: str = Field(index=True, unique=True)
|
||||||
|
hashed_api_key: str = Field(index=True)
|
||||||
# User relationship
|
# User relationship
|
||||||
user_id: UUID = Field(index=True, foreign_key="user.id")
|
user_id: UUID = Field(index=True, foreign_key="user.id")
|
||||||
user: "User" = Relationship(back_populates="api_keys")
|
user: "User" = Relationship(back_populates="api_keys")
|
||||||
|
|
|
||||||
|
|
@ -24,17 +24,20 @@ def create_api_key(
|
||||||
generated_api_key = secrets.token_urlsafe(32)
|
generated_api_key = secrets.token_urlsafe(32)
|
||||||
|
|
||||||
# hash the API key
|
# hash the API key
|
||||||
hashed_api_key = get_password_hash(generated_api_key)
|
hashed = get_password_hash(generated_api_key)
|
||||||
# Use the generated key to create the ApiKey object
|
# Use the generated key to create the ApiKey object
|
||||||
|
masked_api_key = f"{'*' * 10}{generated_api_key[-4:]}"
|
||||||
api_key = ApiKey(api_key=hashed_api_key, name=api_key_create.name, user_id=user_id)
|
api_key = ApiKey(
|
||||||
|
api_key=masked_api_key,
|
||||||
|
hashed_api_key=hashed,
|
||||||
|
name=api_key_create.name,
|
||||||
|
user_id=user_id,
|
||||||
|
)
|
||||||
|
|
||||||
session.add(api_key)
|
session.add(api_key)
|
||||||
session.commit()
|
session.commit()
|
||||||
session.refresh(api_key)
|
session.refresh(api_key)
|
||||||
unmasked = UnmaskedApiKeyRead.from_orm(api_key)
|
return UnmaskedApiKeyRead.from_orm(api_key)
|
||||||
unmasked.api_key = generated_api_key
|
|
||||||
return unmasked
|
|
||||||
|
|
||||||
|
|
||||||
def delete_api_key(session: Session, api_key_id: UUID) -> None:
|
def delete_api_key(session: Session, api_key_id: UUID) -> None:
|
||||||
|
|
|
||||||
|
|
@ -466,9 +466,9 @@ export async function updateUser(user_id: string, user: Users) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getApiKey(user_id: String) {
|
export async function getApiKey() {
|
||||||
try {
|
try {
|
||||||
const res = await api.get(`${BASE_URL_API}api_key/${user_id}`);
|
const res = await api.get(`${BASE_URL_API}api_key`);
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
|
|
@ -478,9 +478,9 @@ export async function getApiKey(user_id: String) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createApiKey(user_id: string) {
|
export async function createApiKey(name:string) {
|
||||||
try {
|
try {
|
||||||
const res = await api.post(`${BASE_URL_API}api_key/${user_id}`);
|
const res = await api.post(`${BASE_URL_API}api_key`,{name});
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
|
|
@ -491,9 +491,9 @@ export async function createApiKey(user_id: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function deleteApiKey(user_id: string) {
|
export async function deleteApiKey(api_key: string) {
|
||||||
try {
|
try {
|
||||||
const res = await api.delete(`${BASE_URL_API}api_key/${user_id}`);
|
const res = await api.delete(`${BASE_URL_API}api_key/${api_key}`);
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ export default function SecretKeyModal({
|
||||||
};
|
};
|
||||||
|
|
||||||
function handleAddNewKey() {
|
function handleAddNewKey() {
|
||||||
createApiKey(data)
|
createApiKey(apiKeyName)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
setApiKeyValue(res["api_key"]);
|
setApiKeyValue(res["api_key"]);
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import { CHAT_FORM_DIALOG_SUBTITLE } from "../../constants/constants";
|
||||||
import { TabsContext } from "../../contexts/tabsContext";
|
import { TabsContext } from "../../contexts/tabsContext";
|
||||||
import { TabsState } from "../../types/tabs";
|
import { TabsState } from "../../types/tabs";
|
||||||
import { validateNodes } from "../../utils/reactflowUtils";
|
import { validateNodes } from "../../utils/reactflowUtils";
|
||||||
|
import { AuthContext } from "../../contexts/authContext";
|
||||||
|
|
||||||
export default function FormModal({
|
export default function FormModal({
|
||||||
flow,
|
flow,
|
||||||
|
|
@ -60,6 +61,7 @@ export default function FormModal({
|
||||||
|
|
||||||
const [chatHistory, setChatHistory] = useState<ChatMessageType[]>([]);
|
const [chatHistory, setChatHistory] = useState<ChatMessageType[]>([]);
|
||||||
const { reactFlowInstance } = useContext(typesContext);
|
const { reactFlowInstance } = useContext(typesContext);
|
||||||
|
const {accessToken} = useContext(AuthContext);
|
||||||
const { setErrorData } = useContext(alertContext);
|
const { setErrorData } = useContext(alertContext);
|
||||||
const ws = useRef<WebSocket | null>(null);
|
const ws = useRef<WebSocket | null>(null);
|
||||||
const [lockChat, setLockChat] = useState(false);
|
const [lockChat, setLockChat] = useState(false);
|
||||||
|
|
@ -160,7 +162,7 @@ export default function FormModal({
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//TODO improve check of user authentication
|
||||||
function getWebSocketUrl(
|
function getWebSocketUrl(
|
||||||
chatId: string,
|
chatId: string,
|
||||||
isDevelopment: boolean = false
|
isDevelopment: boolean = false
|
||||||
|
|
@ -173,7 +175,7 @@ export default function FormModal({
|
||||||
|
|
||||||
return `${
|
return `${
|
||||||
isDevelopment ? "ws" : webSocketProtocol
|
isDevelopment ? "ws" : webSocketProtocol
|
||||||
}://${host}${chatEndpoint}`;
|
}://${host}${chatEndpoint}?token=${accessToken}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleWsMessage(data: any) {
|
function handleWsMessage(data: any) {
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ export default function ApiKeysPage() {
|
||||||
function getKeys() {
|
function getKeys() {
|
||||||
setLoadingKeys(true);
|
setLoadingKeys(true);
|
||||||
if (userData) {
|
if (userData) {
|
||||||
getApiKey(userData.id)
|
getApiKey()
|
||||||
.then((keys: [ApiKey]) => {
|
.then((keys: [ApiKey]) => {
|
||||||
keysList.current = keys["api_keys"];
|
keysList.current = keys["api_keys"];
|
||||||
setUserId(keys["user_id"]);
|
setUserId(keys["user_id"]);
|
||||||
|
|
@ -196,6 +196,7 @@ export default function ApiKeysPage() {
|
||||||
data={api_keys.id}
|
data={api_keys.id}
|
||||||
index={index}
|
index={index}
|
||||||
onConfirm={(index, keys) => {
|
onConfirm={(index, keys) => {
|
||||||
|
console.log(keys);
|
||||||
handleDeleteKey(keys);
|
handleDeleteKey(keys);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue