Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update webinar changes #289

Merged
merged 3 commits into from
Sep 9, 2024
Merged

Update webinar changes #289

merged 3 commits into from
Sep 9, 2024

Conversation

nxtCoder19
Copy link
Contributor

@nxtCoder19 nxtCoder19 commented Sep 9, 2024

Summary by Sourcery

Enhance the webinar application by integrating user authentication, refactor the webinar and meeting pages for better data handling and loading management, update TypeScript configuration, and clean up the codebase by commenting out unused code.

New Features:

  • Introduce user authentication in the webinar app by integrating with an external authentication service to fetch user data and handle redirection based on authentication status.

Enhancements:

  • Refactor the webinar page to use asynchronous functions for handling user data and redirection.
  • Improve the meeting page by wrapping the meeting component in a Suspense component for better loading state management.

Build:

  • Update the TypeScript configuration in the webinar app to include new path mappings and adjust the library settings.

Chores:

  • Comment out unused code and imports across multiple files to clean up the codebase and improve readability.

Copy link

sourcery-ai bot commented Sep 9, 2024

Reviewer's Guide by Sourcery

This pull request updates the webinar application, removes cluster-related code from the console application, and makes various other changes across multiple files. The main focus is on updating the webinar application to handle user authentication and session management, while also removing dependencies on cluster information in the console application.

File-Level Changes

Change Details Files
Updated webinar application to handle user authentication and session management
  • Added axios for API calls
  • Implemented user authentication check
  • Added redirect logic for unauthenticated users
  • Updated JoinWebinar component to use authenticated user data
  • Modified Meeting component to use Suspense for better loading handling
src/apps/webinar/src/app/page.tsx
src/apps/webinar/src/app/components/join-webinar.tsx
src/apps/webinar/src/app/pages/meeting/page.tsx
src/apps/webinar/src/app/api/get-user/route.ts
Removed cluster-related code from console application
  • Commented out cluster-related imports and variables
  • Removed cluster-dependent logic
  • Updated function parameters and return types to exclude cluster information
src/apps/console/page-components/app/compute.tsx
src/apps/console/routes/_main+/$account+/env+/$environment+/routers/handle-router.tsx
src/apps/console/routes/_main+/$account+/env+/$environment+/new-app/app-compute.tsx
src/apps/console/routes/_main+/$account+/env+/$environment+/external-apps/external-app-resource.tsx
src/apps/console/routes/_main+/$account+/env+/$environment+/_layout.tsx
src/apps/console/routes/_main+/$account+/env+/$environment+/apps/apps-resources-v2.tsx
src/apps/console/routes/_main+/$account+/env+/$environment+/managed-resources/managed-resources-resource-v2.tsx
Updated authentication flow in the auth application
  • Modified login route to handle callback parameter
  • Updated login button to use dynamic login URL based on callback presence
src/apps/auth/routes/_providers+/login.tsx
Updated TypeScript configuration for webinar application
  • Added new path mappings
  • Updated compiler options
src/apps/webinar/tsconfig.json

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

@nxtCoder19 nxtCoder19 merged commit da9cbdd into ui/reg-images Sep 9, 2024
3 checks passed
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @nxtCoder19 - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Hardcoded URL found in the code. (link)
  • Hardcoded URL found in the code. (link)

Overall Comments:

  • Please provide a detailed description of the changes and their purpose. The lack of context makes it difficult to understand the motivation behind these modifications.
  • Consider adopting a consistent approach to removing or deprecating code. Currently, some parts are fully removed while others are commented out, which could lead to confusion.
  • Could you explain the testing strategy for these changes? Given the scope of the modifications, it's important to ensure that all affected functionality has been thoroughly tested.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🔴 Security: 2 blocking issues
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

</div>
<div className="bodyMd-medium text-text-soft">
Join webinar and experience the power of Kloudlite
export default async function Home() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider extracting authentication logic into a custom hook.

The Home component has become more complex with the addition of authentication and API call logic. To improve readability and maintainability, consider extracting this logic into a custom hook. This will separate concerns and make the component easier to understand while retaining all new functionality.

Here's an example of how you could refactor this:

// useAuth.ts
import { useState, useEffect } from 'react';
import axios from 'axios';
import { cookies } from 'next/headers';

export function useAuth() {
  const [userData, setUserData] = useState(null);
  const [isLoading, setIsLoading] = useState(true);

  useEffect(() => {
    async function authenticate() {
      const cookie = cookies().get("hotspot-session");
      const callbackUrl = "https://auth-piyush.dev.kloudlite.io";
      const redirectUrl = "https://auth.dev.kloudlite.io/login?callback=" + callbackUrl;

      try {
        const res = await axios({
          url: `${process.env.NEXT_PUBLIC_AUTH_URL}/api` || 'https://auth.kloudlite.io/api',
          method: 'post',
          data: {
            method: 'whoAmI',
            args: [{}],
          },
          headers: {
            'Content-Type': 'application/json; charset=utf-8',
            connection: 'keep-alive',
            cookie: 'hotspot-session=' + cookie?.value + ';',
          },
        });
        setUserData(res.data.data);
      } catch (e) {
        window.location.href = redirectUrl;
      } finally {
        setIsLoading(false);
      }
    }

    authenticate();
  }, []);

  return { userData, isLoading };
}

// Home.tsx
import { useAuth } from './useAuth';
import { JoinWebinar } from './components/join-webinar';

export default function Home() {
  const { userData, isLoading } = useAuth();

  if (isLoading) {
    return <div>Loading...</div>;
  }

  if (!userData) {
    return null; // or a loading state, this will be brief before redirect
  }

  return (
    <main className='flex flex-col h-full'>
      <div className='flex flex-1 flex-col md:items-center self-stretch justify-center px-3xl py-5xl md:py-9xl'>
        <div className='flex flex-col gap-3xl md:w-[500px] px-3xl py-5xl md:px-9xl'>
          <div className='flex flex-col items-stretch"'>
            <div className="flex flex-col gap-lg items-center pb-6xl text-center">
              <div className={cn('text-text-strong headingXl text-center')}>
                Join Kloudlite webinar
              </div>
              <div className="bodyMd-medium text-text-soft">
                Join webinar and experience the power of Kloudlite
              </div>
            </div>
            <JoinWebinar userData={userData} />
            {userData.email}
          </div>
        </div>
      </div>
    </main>
  );
}

This refactoring:

  1. Extracts authentication logic into a useAuth hook.
  2. Simplifies the Home component, focusing it on rendering.
  3. Handles loading and error states more explicitly.
  4. Improves reusability of the authentication logic.

Remember to adjust imports and types as necessary for your project structure.

export default async function Home() {

const cookie = cookies().get("hotspot-session")
const callbackUrl = "https://auth-piyush.dev.kloudlite.io";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 issue (security): Hardcoded URL found in the code.

Consider using an environment variable to store URLs to avoid hardcoding them in the codebase.


const cookie = cookies().get("hotspot-session")
const callbackUrl = "https://auth-piyush.dev.kloudlite.io";
const redirectUrl = "https://auth.dev.kloudlite.io/login?callback=" + callbackUrl;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 issue (security): Hardcoded URL found in the code.

Consider using an environment variable to store URLs to avoid hardcoding them in the codebase.

cookie: 'hotspot-session=' + cookie?.value + ';',
},
});
const data = res.data.data;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Prefer object destructuring when accessing and using properties. (use-object-destructuring)

Suggested change
const data = res.data.data;
const {data} = res.data;


ExplanationObject destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.

From the Airbnb Javascript Style Guide

@nxtCoder19 nxtCoder19 deleted the update/env-context branch September 23, 2024 07:29
abdheshnayak pushed a commit that referenced this pull request Oct 28, 2024
tulsiojha pushed a commit that referenced this pull request Nov 1, 2024
abdheshnayak pushed a commit that referenced this pull request Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant