Add optional Clerk authentication - #13
Conversation
|
Hi! I'm the It looks like you correctly set up a CI job that uses the autofix.ci GitHub Action, but the autofix.ci GitHub App has not been installed for this repository. This means that autofix.ci unfortunately does not have the permissions to fix this pull request. If you are the repository owner, please install the app and then restart the CI workflow! 😃 |
* refactor: update auth and login pages to signup users * updated imports in clerk_utils.py * modified clerk_auth and login-page.tsx * updated context-wrapper * updated context-wrapper * modified use-post-refresh-access.ts * add new file for clerk constants * modified autologin for clerk auth * add token refresh effect in auth.tsx
| @@ -0,0 +1,6 @@ | |||
| // src/clerk/constants.ts | |||
There was a problem hiding this comment.
Move all these constants into
src/frontend/src/clerk/auth.tsx file and import its reference from the above same file
| } catch (err: any) { | ||
| const status = err?.response?.status; | ||
| console.warn(`[ensureLangflowUser] whoami failed (${status})`); | ||
| if (status === 401) { |
There was a problem hiding this comment.
instead of 401 - use a HTTP ERROR CODE ENUM
| justCreated: boolean; | ||
| user: Users | null; | ||
| }> { | ||
| console.log("[ensureLangflowUser] START"); |
There was a problem hiding this comment.
Remove this log
| return; | ||
| }else{ | ||
| console.log("[ClerkAuthAdapter] Clerk token changed, syncing..."); | ||
| cookie.set(LANGFLOW_ACCESS_TOKEN, token, { path: "/" }); |
There was a problem hiding this comment.
instead of these two lines
cookie.set(LANGFLOW_ACCESS_TOKEN, token, { path: "/" });
useAuthStore.getState().setAccessToken?.(token); // if you have this
can we use the login function?
login(token,<other parameters>)?
There was a problem hiding this comment.
sir, those were added for refresh logic, since we now have separate useEffect we dont need that if else block.
| prevTokenRef.current = token; | ||
| const current = cookie.get(LANGFLOW_ACCESS_TOKEN); | ||
| if (token !== current) { | ||
| cookie.set(LANGFLOW_ACCESS_TOKEN, token, { path: "/" }); |
There was a problem hiding this comment.
Should we use the login function?
login(token, <other parameters>)
Instead of
cookie.set(LANGFLOW_ACCESS_TOKEN, token, { path: "/" });
useAuthStore.getState().setAccessToken?.(token);
e67d350 to
11c0fdb
Compare
* added protected paths in login api * added bearer token in header * ruff check fix
| import { LANGFLOW_ACCESS_TOKEN } from "@/constants/constants"; | ||
| import { Cookies } from "react-cookie"; | ||
|
|
||
| console.log(useAuthStore.getState().isAuthenticated, "useAuthStore.isAuthenticated"); |
| import MessagesPage from "./pages/SettingsPage/pages/messagesPage"; | ||
| import ShortcutsPage from "./pages/SettingsPage/pages/ShortcutsPage"; | ||
| import ViewPage from "./pages/ViewPage"; | ||
| import { LoginPage, SignUpPage, LoginAdminPage } from "./clerk/login-pages"; |
There was a problem hiding this comment.
Import as
import { LoginPage, SignUp, LoginAdminPage } from "./clerk/login-pages";
| element={ | ||
| <ProtectedLoginRoute> | ||
| <SignUp /> | ||
| <SignUpPage /> |
There was a problem hiding this comment.
We don't need this change anymore
| @@ -0,0 +1,70 @@ | |||
| import { useCustomNavigate } from "@/customization/hooks/use-custom-navigate"; | |||
| import { SignIn, SignUp, useAuth, useUser , useClerk, SignedOut} from "@clerk/clerk-react"; | |||
There was a problem hiding this comment.
Apply this diff
@@ function ClerkSignUpPage() {
useEffect(() => {
async function handleSignup() {
if (isSignedIn && user && !processed) {
- console.log("[ClerkSignUpPage] User is signed in, processing sign up...");
+ console.debug("[ClerkSignUpPage] User is signed in, processing sign up...");
setProcessed(true);
const token = await getToken();
if (token) {
const username =
user.username || user.primaryEmailAddress?.emailAddress || user.id;
- console.log(`[ClerkSignUpPage] Creating Langflow user for: ${username}`);
+ console.debug(`[ClerkSignUpPage] Creating Langflow user for: ${username}`);
await ensureLangflowUser(token, username);
} else {
- console.log("[ClerkSignUpPage] No token received from Clerk.");
+ console.warn("[ClerkSignUpPage] No token received from Clerk.");
}
- console.log("[ClerkSignUpPage] Signing out user after sign up.");
+ console.debug("[ClerkSignUpPage] Signing out user after sign up.");
await logout();
- console.log("[ClerkSignUpPage] Redirecting to /login after sign up.");
+ console.debug("[ClerkSignUpPage] Redirecting to /login after sign up.");
navigate("/login");
}
}
| if (!isLoginPage) { | ||
| const status = error.response?.status; | ||
| if (status === 400 && IS_CLERK_AUTH) { | ||
| console.log("[AutoLogin] Clerk login - skipping logout on 400"); |
There was a problem hiding this comment.
Make it console.debug
| path="signup" | ||
| element={ | ||
| <ProtectedLoginRoute> | ||
| <SignUp /> |
There was a problem hiding this comment.
We should not have this change
* update make file to inject build args in docker * update docker file to load env * modified constant.ts * Update Makefile and Dockerfile to replace LANGFLOW_AUTO_LOGIN with VITE_AUTO_LOGIN * modified constant.ts

Summary
ClerkAuthProviderwhenIS_CLERK_AUTHis true.env.clerk.examplefor Clerk configuration.env.exampleTesting
npm run type-check(fails: Cannot find module 'react')make tests_frontend(fails: playwright installation prompt)https://chatgpt.com/codex/tasks/task_e_6868e3a90fdc8326a9ff235d844cc057