From 32bded7da8c7ca5ce35eb0cd536ddeb4e23a981f Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Thu, 10 Apr 2025 12:52:37 -0700 Subject: [PATCH] fix(landing): show workflows for users that have been approved & logged in --- .../components/social-login-buttons.tsx | 10 +++++ sim/app/(auth)/login/login-form.tsx | 5 +++ sim/app/(auth)/verify/verify-content.tsx | 10 +++++ sim/app/(landing)/components/nav-client.tsx | 43 ++++++++++++++++++- sim/providers/xai/index.ts | 1 - 5 files changed, 67 insertions(+), 2 deletions(-) diff --git a/sim/app/(auth)/components/social-login-buttons.tsx b/sim/app/(auth)/components/social-login-buttons.tsx index b7b3a1993..dd3a9be08 100644 --- a/sim/app/(auth)/components/social-login-buttons.tsx +++ b/sim/app/(auth)/components/social-login-buttons.tsx @@ -30,6 +30,11 @@ export function SocialLoginButtons({ setIsGithubLoading(true) try { await client.signIn.social({ provider: 'github', callbackURL }) + + // Mark that the user has previously logged in + if (typeof window !== 'undefined') { + localStorage.setItem('has_logged_in_before', 'true') + } } catch (err: any) { let errorMessage = 'Failed to sign in with GitHub' @@ -55,6 +60,11 @@ export function SocialLoginButtons({ setIsGoogleLoading(true) try { await client.signIn.social({ provider: 'google', callbackURL }) + + // Mark that the user has previously logged in + if (typeof window !== 'undefined') { + localStorage.setItem('has_logged_in_before', 'true') + } } catch (err: any) { let errorMessage = 'Failed to sign in with Google' diff --git a/sim/app/(auth)/login/login-form.tsx b/sim/app/(auth)/login/login-form.tsx index 09aef6e47..bbf32e27e 100644 --- a/sim/app/(auth)/login/login-form.tsx +++ b/sim/app/(auth)/login/login-form.tsx @@ -118,6 +118,11 @@ export default function LoginPage({ setIsLoading(false) return } + + // Mark that the user has previously logged in + if (typeof window !== 'undefined') { + localStorage.setItem('has_logged_in_before', 'true') + } } catch (err: any) { // Handle only the special verification case that requires a redirect if (err.message?.includes('not verified') || err.message?.includes('EMAIL_NOT_VERIFIED')) { diff --git a/sim/app/(auth)/verify/verify-content.tsx b/sim/app/(auth)/verify/verify-content.tsx index cfd70ece6..79e1b45cb 100644 --- a/sim/app/(auth)/verify/verify-content.tsx +++ b/sim/app/(auth)/verify/verify-content.tsx @@ -165,6 +165,16 @@ export function VerifyContent({ hasResendKey, baseUrl, isProduction }: VerifyCon }> + + {/* Login link for already verified users */} + +

+ Already have an account? Go to{' '} + + Login + +

+
) } diff --git a/sim/app/(landing)/components/nav-client.tsx b/sim/app/(landing)/components/nav-client.tsx index 6d63f4052..c9dbb2ca3 100644 --- a/sim/app/(landing)/components/nav-client.tsx +++ b/sim/app/(landing)/components/nav-client.tsx @@ -1,7 +1,14 @@ 'use client' +import { useEffect, useState } from 'react' +import Link from 'next/link' +import { Button } from '@/components/ui/button' +import { useSession } from '@/lib/auth-client' +import { createLogger } from '@/lib/logs/console-logger' import { useWindowSize } from './use-window-size' +const logger = createLogger('NavClient') + const XIcon = () => ( ( export default function NavClient({ children }: { children: React.ReactNode }) { const { width } = useWindowSize() const isMobile = width !== undefined && width < 640 + const { data: session } = useSession() + const isAuthenticated = !!session?.user + const [hasPreviouslyLoggedIn, setHasPreviouslyLoggedIn] = useState(false) + + // Check if user has previously logged in + useEffect(() => { + // Check localStorage for previous login flag + if (typeof window !== 'undefined') { + const hasLoggedInBefore = localStorage.getItem('has_logged_in_before') === 'true' + setHasPreviouslyLoggedIn(hasLoggedInBefore) + } + + // If user is currently authenticated, set the flag for future visits + if (isAuthenticated && typeof window !== 'undefined') { + localStorage.setItem('has_logged_in_before', 'true') + } + }, [isAuthenticated]) return (
sim studio
- {/* Social media icons */} + {/* Navigation and social media icons */}
+ {isAuthenticated ? ( + + workflows + + ) : ( + hasPreviouslyLoggedIn && ( + + login + + ) + )}