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

zitadel #15

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

zitadel #15

wants to merge 15 commits into from

Conversation

Palabola
Copy link
Contributor

@Palabola Palabola commented May 23, 2024

Summary by CodeRabbit

  • New Features
    • Introduced an authentication guard to control access based on user authentication status.
    • Added OAuth-based user authentication, including methods to manage tokens, check login status, and sign out.

Copy link
Contributor

coderabbitai bot commented May 23, 2024

Walkthrough

The changes introduce an authentication guard and enhance the AuthenticationService in an Angular application to integrate ZITADEL OAuth authentication. The guard ensures access control based on user authentication status, while the service manages login flows, token handling, and user information retrieval.

Changes

Files/Paths Change Summary
src/app/guards/auth.guard.ts Added an authGuard using CanActivateFn to control access based on authentication status.
src/app/services/authentication.service.ts Enhanced AuthenticationService with methods for login, token management, and user information retrieval.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant AuthGuard
    participant AuthenticationService
    participant ZITADEL

    User->>AuthGuard: Access Protected Route
    AuthGuard->>AuthenticationService: Check Authentication Status
    AuthenticationService-->>AuthGuard: Return Status
    AuthGuard-->>User: Allow/Deny Access

    User->>AuthenticationService: Initiate Login
    AuthenticationService->>ZITADEL: OAuth Login Request
    ZITADEL-->>AuthenticationService: OAuth Tokens
    AuthenticationService-->>User: Store Tokens and Redirect
Loading

Assessment against linked issues

Objective Addressed Explanation
Integrate ZITADEL auth (DEV-149)

Poem

In code we trust, with ZITADEL's might,
Authentication now takes flight.
Guards in place, to keep us secure,
Tokens and logins, seamless and pure.
Angular's heart beats strong and true,
With every change, our app renews.
🌟🚀🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented May 23, 2024

Deploy Preview for creative-choux-a3c817 failed. Why did it fail? →

Name Link
🔨 Latest commit 382ca64
🔍 Latest deploy log https://app.netlify.com/sites/creative-choux-a3c817/deploys/665867c75beec700083ad70f

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

Outside diff range and nitpick comments (1)
src/app/services/authentication.service.ts (1)

17-19: Ensure that logging OAuth events to the console is intended for production. Consider using a more sophisticated logging mechanism if needed.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 3aeacb6 and 0cb1e46.
Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (18)
  • README.md (1 hunks)
  • package.json (2 hunks)
  • src/app/app.component.ts (4 hunks)
  • src/app/app.config.ts (2 hunks)
  • src/app/app.routes.ts (1 hunks)
  • src/app/auth/callback/callback.component.html (1 hunks)
  • src/app/auth/callback/callback.component.scss (1 hunks)
  • src/app/auth/callback/callback.component.spec.ts (1 hunks)
  • src/app/auth/callback/callback.component.ts (1 hunks)
  • src/app/layout/header/header.component.html (3 hunks)
  • src/app/layout/header/header.component.ts (1 hunks)
  • src/app/pages/landingpage/landingpage.component.html (1 hunks)
  • src/app/pages/server-details/server-details.component.html (3 hunks)
  • src/app/pages/server-listing/server-listing.component.html (8 hunks)
  • src/app/services/analytics.service.ts (1 hunks)
  • src/app/services/authentication.service.spec.ts (1 hunks)
  • src/app/services/authentication.service.ts (1 hunks)
  • src/main.ts (1 hunks)
Files not summarized due to errors (4)
  • README.md: Error: Server error. Please try again later.
  • src/app/services/authentication.service.ts: Error: Server error. Please try again later.
  • src/main.ts: Error: Server error. Please try again later.
  • src/app/app.config.ts: Error: Server error. Please try again later.
Files skipped from review due to trivial changes (7)
  • package.json
  • src/app/auth/callback/callback.component.html
  • src/app/auth/callback/callback.component.scss
  • src/app/pages/landingpage/landingpage.component.html
  • src/app/pages/server-details/server-details.component.html
  • src/app/pages/server-listing/server-listing.component.html
  • src/app/services/authentication.service.spec.ts
Additional Context Used
LanguageTool (1)
README.md (1)

Near line 22: In American English, abbreviations like “etc.” require a period.
Context: ...o anonymously track page visits, clicks etc via the following environment variables...

Markdownlint (1)
README.md (1)

26: null
Bare URL used

Additional comments not posted (12)
src/main.ts (1)

6-6: Bootstrap function usage looks correct and is properly handling errors.

src/app/layout/header/header.component.ts (2)

4-5: Component setup with necessary imports and standalone configuration looks good.

Also applies to: 10-10


16-31: Ensure that the methods isLoggedIn, authenticate, and signout in AuthenticationService are implemented as expected and handle all authentication states correctly.

Verification successful

The methods isLoggedIn, authenticate, and signout are implemented in the AuthenticationService class as follows:

  • isLoggedIn: Checks if there is a valid access token.
  • authenticate: Configures the OAuth service and initiates the login process if there is no valid ID token.
  • signout: Logs out the user by calling the OAuth service's logOut method.

These methods appear to handle authentication states correctly.

  • isLoggedIn method:

    public isLoggedIn(): boolean {
      return this.oauthService.hasValidAccessToken();
    }
  • authenticate method:

    public async authenticate(setState: boolean = true): Promise<void> {
      this.oauthService.configure(this.authConfig);
      this.oauthService.setupAutomaticSilentRefresh();
      this.oauthService.strictDiscoveryDocumentValidation = false;
      await this.oauthService.loadDiscoveryDocumentAndTryLogin();
    
      if (!this.oauthService.hasValidIdToken()) {
        const newState = undefined; //setState ? await this.statehandler.createState().toPromise() : undefined;
        this.oauthService.initCodeFlow(newState);
      }
    
      return;
    }
  • signout method:

    public signout(): void {
      this.oauthService.logOut();
    }

These implementations align with the expected behavior for handling authentication states.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation of authentication methods.

# Test: Search for the implementation of `isLoggedIn`, `authenticate`, and `signout` methods.
ast-grep --lang typescript --pattern $'class AuthenticationService {
  $$$
  isLoggedIn($_) {
    $$$
  }
  authenticate($_) {
    $$$
  }
  signout($_) {
    $$$
  }
  $$$
}'

Length of output: 176



Script:

#!/bin/bash
# Description: Verify the existence and implementation of authentication methods in AuthenticationService.

# Step 1: Search for the AuthenticationService class.
ast-grep --lang typescript --pattern $'class AuthenticationService {
  $$$
}'

# Step 2: Search for the isLoggedIn method within AuthenticationService.
ast-grep --lang typescript --pattern $'class AuthenticationService {
  $$$
  isLoggedIn() {
    $$$
  }
  $$$
}'

# Step 3: Search for the authenticate method within AuthenticationService.
ast-grep --lang typescript --pattern $'class AuthenticationService {
  $$$
  authenticate() {
    $$$
  }
  $$$
}'

# Step 4: Search for the signout method within AuthenticationService.
ast-grep --lang typescript --pattern $'class AuthenticationService {
  $$$
  signout() {
    $$$
  }
  $$$
}'

Length of output: 4153

src/app/auth/callback/callback.component.ts (1)

1-39: Callback component setup with necessary imports and standalone configuration looks good. Ensure that the authentication flow in loginCodeFlow and token handling are implemented as expected and handle all edge cases.

Verification successful

The loginCodeFlow and getToken methods are implemented in src/app/services/authentication.service.ts. Ensure that these methods handle the authentication flow and token management correctly.

  • loginCodeFlow method: src/app/services/authentication.service.ts: public async loginCodeFlow(): Promise<void>
  • getToken method: src/app/services/authentication.service.ts: public async getToken(): Promise<string>
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation of `loginCodeFlow` and token handling.

# Test: Search for the implementation of `loginCodeFlow` and token handling methods.
ast-grep --lang typescript --pattern $'class AuthenticationService {
  $$$
  loginCodeFlow($_) {
    $$$
  }
  getToken($_) {
    $$$
  }
  $$$
}'

Length of output: 147



Script:

#!/bin/bash
# Description: Verify the implementation of `loginCodeFlow` and token handling methods separately.

# Test: Search for the implementation of `loginCodeFlow` method.
ast-grep --lang typescript --pattern $'class $_ {
  $$$
  loginCodeFlow($_) {
    $$$
  }
  $$$
}'

# Test: Search for the implementation of `getToken` method.
ast-grep --lang typescript --pattern $'class $_ {
  $$$
  getToken($_) {
    $$$
  }
  $$$
}'

Length of output: 194



Script:

#!/bin/bash
# Description: Verify the implementation of `loginCodeFlow` and `getToken` methods by searching for their names directly.

# Test: Search for the `loginCodeFlow` method name in the codebase.
rg 'loginCodeFlow' --type ts

# Test: Search for the `getToken` method name in the codebase.
rg 'getToken' --type ts

Length of output: 420

src/app/app.routes.ts (1)

15-15: The new route for the authentication callback is correctly configured to dynamically load the CallbackComponent.

src/app/services/authentication.service.ts (5)

22-24: This method effectively wraps the OAuth profile loading in an Observable. Good use of RxJS!


30-30: Setting strictDiscoveryDocumentValidation to false can lead to security vulnerabilities. Ensure this is safe in your deployment environment or consider enabling it.


47-49: Method to retrieve the ID token is implemented correctly.


51-53: Correct implementation for checking the login status based on the access token's validity.


55-57: The signout method is straightforward and effectively logs out the user.

src/app/app.config.ts (1)

9-9: OAuth configuration and AuthConfig setup are correctly implemented. Verify that the client details and URLs are appropriate for your environment.

Also applies to: 15-26, 83-91, 111-113

src/app/layout/header/header.component.html (1)

17-17: Updates to the navigation links and conditional rendering of login/logout buttons are implemented correctly. Verify the dynamic rendering during testing.

Also applies to: 23-23, 50-64, 80-80, 86-86

Verification successful

The header.component.ts file contains the isLoggedIn() method, which relies on the AuthenticationService to determine the user's authentication status. This confirms that the dynamic rendering of login/logout buttons is correctly implemented based on the user's authentication status.

  • header.component.ts:
    • isLoggedIn() { return this.authService.isLoggedIn(); }
    • import { AuthenticationService } from '../../services/authentication.service';
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the dynamic rendering of login/logout buttons based on the user's authentication status.

# Test: Search for conditional rendering logic in the HeaderComponent. Expect: Correct implementation of conditional rendering based on authentication status.
rg --type html $'\*ngIf="isLoggedIn\(\)"'

Length of output: 131



Script:

#!/bin/bash
# Description: Verify the implementation of the isLoggedIn() method in the HeaderComponent.

# Locate the TypeScript file for HeaderComponent
header_ts_file=$(fd header.component.ts)

# Search for the implementation of the isLoggedIn() method in the located TypeScript file
ast-grep --lang typescript --pattern 'isLoggedIn() { $$$ }' $header_ts_file

Length of output: 631



Script:

#!/bin/bash
# Description: Verify the implementation of the isLoggedIn() method in the HeaderComponent.

# Locate the TypeScript file for HeaderComponent
header_ts_file=$(fd header.component.ts)

# Search for the implementation of the isLoggedIn() method in the located TypeScript file
ast-grep --lang typescript --pattern 'function isLoggedIn() { $$$ }' $header_ts_file || \
ast-grep --lang typescript --pattern 'isLoggedIn() { $$$ }' $header_ts_file

Length of output: 197



Script:

#!/bin/bash
# Description: Search for the isLoggedIn method across all TypeScript files in the repository.

# Search for the implementation of the isLoggedIn method in all TypeScript files
ast-grep --lang typescript --pattern 'function isLoggedIn() { $$$ }' || \
ast-grep --lang typescript --pattern 'isLoggedIn() { $$$ }'

Length of output: 70



Script:

#!/bin/bash
# Description: Search for authentication-related methods and imports in the HeaderComponent.

# Locate the TypeScript file for HeaderComponent
header_ts_file=$(fd header.component.ts)

# Search for any method related to authentication status in the located TypeScript file
rg 'isLoggedIn|auth|login|logout' $header_ts_file

# Search for any imported services or methods related to authentication in the located TypeScript file
rg 'import.*auth' $header_ts_file

Length of output: 582

src/main.ts Show resolved Hide resolved
src/app/services/authentication.service.ts Outdated Show resolved Hide resolved
}

public async loginCodeFlow(): Promise<void> {
const newState = undefined; //await this.statehandler.createState().toPromise();
Copy link
Contributor

Choose a reason for hiding this comment

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

Revisit the state management for the login code flow if necessary, as it's currently commented out.

Would you like me to help implement the state management for this flow?

README.md Outdated Show resolved Hide resolved
Comment on lines 1 to 6
import { isPlatformBrowser } from '@angular/common';
import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import posthog from 'posthog-js'

const POSTHOG_KEY = import.meta.env['NG_APP_POSTHOG_KEY'];
const POSTHOG_HOST = import.meta.env['NG_APP_POSTHOG_HOST'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The environment variables NG_APP_POSTHOG_KEY and NG_APP_POSTHOG_HOST are not set, which could cause issues with the PostHog analytics service initialization. Please ensure these environment variables are correctly defined and accessible in your deployment environment.

Analysis chain

Analytics service setup with environment variable imports and tracking methods looks well-implemented. Ensure that the environment variables NG_APP_POSTHOG_KEY and NG_APP_POSTHOG_HOST are correctly set in the deployment environment.

Also applies to: 13-34

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the environment variables for PostHog analytics.

# Test: Check if the environment variables are set.
echo $NG_APP_POSTHOG_KEY
echo $NG_APP_POSTHOG_HOST

Length of output: 15

@@ -6,6 +6,7 @@ import { initFlowbite } from 'flowbite';
import { register } from 'swiper/element/bundle';
import { HeaderComponent } from './layout/header/header.component';
import { FooterComponent } from './layout/footer/footer.component';
import { AnalyticsService } from './services/analytics.service';
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The codebase includes checks for isPlatformBrowser(this.platformId) in both src/app/app.component.ts and src/app/pages/landingpage/landingpage.component.ts. However, there is no clear indication of environment-specific configurations for analytics initialization.

  • src/app/app.component.ts initializes tracking in ngAfterViewInit if the platform is a browser.
  • src/app/pages/landingpage/landingpage.component.ts fetches articles if the platform is a browser.

There is no explicit differentiation between production and other environments in the provided context.

  • src/app/app.component.ts
  • src/app/pages/landingpage/landingpage.component.ts
Analysis chain

The integration of AnalyticsService for tracking page views is implemented correctly. Ensure that the tracking is configured appropriately for different environments.

Also applies to: 24-24, 38-38, 58-60

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the analytics initialization is configured for production environments.

# Test: Search for environment-specific configurations in the codebase. Expect: Configurations that differentiate between production and other environments.
rg --type typescript $'if \(isPlatformBrowser\(this.platformId\)\) \{'

Length of output: 106



Script:

#!/bin/bash
# Description: Verify that the analytics initialization is configured for production environments.

# Test: Search for environment-specific configurations in the codebase. Expect: Configurations that differentiate between production and other environments.
rg --type ts 'if \(isPlatformBrowser\(this.platformId\)\) \{'

Length of output: 302



Script:

#!/bin/bash
# Description: Review the relevant lines in the identified files to check for environment-specific configurations.

# Display the relevant lines in `src/app/app.component.ts`
rg --type ts --context 5 'if \(isPlatformBrowser\(this.platformId\)\) \{' src/app/app.component.ts

# Display the relevant lines in `src/app/pages/landingpage/landingpage.component.ts`
rg --type ts --context 5 'if \(isPlatformBrowser\(this.platformId\)\) \{' src/app/pages/landingpage/landingpage.component.ts

Length of output: 974

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 0cb1e46 and 84a5d2e.
Files selected for processing (4)
  • src/app/auth/callback/callback.component.ts (1 hunks)
  • src/app/layout/header/header.component.html (3 hunks)
  • src/app/layout/header/header.component.ts (1 hunks)
  • src/app/services/authentication.service.ts (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • src/app/auth/callback/callback.component.ts
  • src/app/layout/header/header.component.html
  • src/app/layout/header/header.component.ts
Additional comments not posted (7)
src/app/services/authentication.service.ts (7)

5-5: Consider removing commented code if StatehandlerService is no longer used.

Also applies to: 15-15


22-24: Method implementation for retrieving OIDC user profile is correct.


30-30: Verify the necessity of disabling strictDiscoveryDocumentValidation as it might pose a security risk.


43-45: Method implementation for handling login code flow is correct.


47-49: Method implementation for retrieving the ID token is correct.


51-53: Method implementation for checking login status is correct.


55-57: Method implementation for handling user signout is correct.

src/app/services/authentication.service.ts Outdated Show resolved Hide resolved
Comment on lines 21 to 22
redirectUri: 'http://localhost:4200/auth/callback',
postLogoutRedirectUri: 'http://localhost:4200/',
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't be hardcoded

src/app/app.config.ts Outdated Show resolved Hide resolved
# Conflicts:
#	package-lock.json
#	package.json
#	src/app/app.config.ts
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Outside diff range and nitpick comments (1)
src/app/app.config.browser.ts (1)

9-9: Consider the security implications of using localStorage for OAuth tokens, as it is vulnerable to XSS attacks. Explore more secure alternatives like sessionStorage or secure cookies.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 84a5d2e and edf3efb.
Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (6)
  • package.json (1 hunks)
  • src/app/app.config.browser.ts (1 hunks)
  • src/app/app.config.ts (2 hunks)
  • src/app/app.routes.ts (1 hunks)
  • src/app/layout/header/header.component.html (1 hunks)
  • src/app/services/authentication.service.ts (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • package.json
  • src/app/layout/header/header.component.html
Additional Context Used
Biome (10)
src/app/app.config.browser.ts (1)

1-1: Some named imports are only used as types.

src/app/app.config.ts (5)

12-12: The computed expression can be simplified without the use of a string literal.


13-13: The computed expression can be simplified without the use of a string literal.


14-14: The computed expression can be simplified without the use of a string literal.


15-15: The computed expression can be simplified without the use of a string literal.


1-1: Some named imports are only used as types.

src/app/app.routes.ts (1)

1-1: All these imports are only used as types.

src/app/services/authentication.service.ts (3)

26-26: Unexpected any. Specify a different type.


1-2: All these imports are only used as types.


2-3: Some named imports are only used as types.

Additional comments not posted (1)
src/app/app.routes.ts (1)

15-17: The new routes for authentication callback and dashboard are correctly implemented using lazy loading. Good job on enhancing performance with this approach.

src/app/services/authentication.service.ts Outdated Show resolved Hide resolved
src/app/services/authentication.service.ts Outdated Show resolved Hide resolved
Comment on lines +12 to +28
const ZITADEL_CLIENT_ID = import.meta.env['NG_APP_ZITADEL_CLIENT_ID'];
const ZITADEL_DOMAIN = import.meta.env['NG_APP_ZITADEL_DOMAIN'];
const ZITADEL_USERINFO_ENDPOINT = import.meta.env['NG_APP_ZITADEL_USERINFO_ENDPOINT'];
const DOMAIN_BASE_URL = import.meta.env['NG_APP_DOMAIN_BASE_URL'];

const authConfig: AuthConfig = {
scope: 'openid profile email offline_access',
responseType: 'code',
oidc: true,
clientId: ZITADEL_CLIENT_ID,
issuer: ZITADEL_DOMAIN,
redirectUri: `${DOMAIN_BASE_URL}auth/callback`,
postLogoutRedirectUri: `${DOMAIN_BASE_URL}`,
requireHttps: false, // required for running locally
tokenEndpoint: `${ZITADEL_DOMAIN}/oauth/v2/token`,
userinfoEndpoint: ZITADEL_USERINFO_ENDPOINT,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Document the OAuth configuration settings in the README.md to ensure they are easily understandable and maintainable.

issuer: ZITADEL_DOMAIN,
redirectUri: `${DOMAIN_BASE_URL}auth/callback`,
postLogoutRedirectUri: `${DOMAIN_BASE_URL}`,
requireHttps: false, // required for running locally
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure requireHttps is set to true in production to enhance security by enforcing HTTPS.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between edf3efb and 2640805.
Files selected for processing (11)
  • src/app/app.component.ts (2 hunks)
  • src/app/app.routes.ts (2 hunks)
  • src/app/auth/callback/callback.component.ts (1 hunks)
  • src/app/guards/auth.guard.spec.ts (1 hunks)
  • src/app/guards/auth.guard.ts (1 hunks)
  • src/app/layout/header/header.component.html (1 hunks)
  • src/app/pages/my-spare-cores/my-spare-cores.component.html (1 hunks)
  • src/app/pages/my-spare-cores/my-spare-cores.component.scss (1 hunks)
  • src/app/pages/my-spare-cores/my-spare-cores.component.spec.ts (1 hunks)
  • src/app/pages/my-spare-cores/my-spare-cores.component.ts (1 hunks)
  • src/app/services/authentication.service.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/app/layout/header/header.component.html
Additional Context Used
Biome (20)
src/app/app.component.ts (7)

22-22: Decorators are not valid here.


23-23: Decorators are not valid here.


1-2: Some named imports are only used as types.


2-3: All these imports are only used as types.


3-4: Some named imports are only used as types.


8-9: All these imports are only used as types.


9-10: All these imports are only used as types.

src/app/app.routes.ts (1)

1-1: All these imports are only used as types.

src/app/auth/callback/callback.component.ts (4)

16-16: Decorators are not valid here.


1-1: Some named imports are only used as types.


1-2: All these imports are only used as types.


2-3: Some named imports are only used as types.

src/app/guards/auth.guard.spec.ts (1)

1-2: All these imports are only used as types.

src/app/guards/auth.guard.ts (2)

15-18: This else clause can be omitted because previous branches break early.


1-1: All these imports are only used as types.

src/app/pages/my-spare-cores/my-spare-cores.component.spec.ts (1)

1-1: Some named imports are only used as types.

src/app/pages/my-spare-cores/my-spare-cores.component.ts (1)

1-2: Some named imports are only used as types.

src/app/services/authentication.service.ts (3)

31-31: Unexpected any. Specify a different type.


1-2: All these imports are only used as types.


2-3: Some named imports are only used as types.

Additional comments not posted (11)
src/app/guards/auth.guard.spec.ts (1)

1-17: The test setup and execution for authGuard are correctly implemented.

src/app/pages/my-spare-cores/my-spare-cores.component.spec.ts (1)

1-23: The test setup and execution for MySpareCoresComponent are correctly implemented.

src/app/auth/callback/callback.component.ts (1)

1-33: The implementation of the authentication callback logic in CallbackComponent is correctly handled.

src/app/pages/my-spare-cores/my-spare-cores.component.html (1)

1-33: The HTML structure and content for MySpareCoresComponent are well-designed and provide a good user experience.

src/app/app.routes.ts (2)

16-21: The new routes for authentication callback and dashboard are correctly configured. Ensure that the authGuard is thoroughly tested to secure the dashboard route.


4-4: Ensure authGuard is properly imported and implemented.

Verification successful

The authGuard is properly implemented in src/app/guards/auth.guard.ts. The implementation uses Angular's CanActivateFn and checks the authentication state using AuthenticationService.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation of `authGuard`.

# Test: Search for the implementation of `authGuard`. Expect: Implementation details of `authGuard`.
rg --type typescript 'authGuard' --files-with-matches

Length of output: 88



Script:

#!/bin/bash
# Description: Verify the implementation of `authGuard`.

# Test: Search for the implementation of `authGuard`. Expect: Implementation details of `authGuard`.
rg --type ts 'authGuard' --files-with-matches

Length of output: 130



Script:

#!/bin/bash
# Description: Extract the implementation details of `authGuard`.

# Test: Display the contents of `src/app/guards/auth.guard.ts` to verify the implementation of `authGuard`.
cat src/app/guards/auth.guard.ts

Length of output: 631

src/app/pages/my-spare-cores/my-spare-cores.component.scss (4)

1-39: The styles for .filter_bar and its child elements are well-organized and follow good CSS practices. Ensure that the transition effects and positioning meet the design requirements.


41-44: The .filter_bar.collapsed class correctly handles the collapsed state by setting the width to 0. This is a good use of CSS for responsive design.


46-71: The styles for .top_buttons and .items_table are consistent and use modern CSS practices with @apply directive for utility classes. Ensure that the responsive behavior is as expected.


82-94: The .dropdown_button and .unit classes are styled appropriately. Check the positioning and transformation effects in different browsers to ensure cross-browser compatibility.

src/app/app.component.ts (1)

24-24: Ensure that the AuthenticationService is correctly injected and utilized within the component. This is crucial for managing user authentication effectively.

src/app/services/authentication.service.ts Outdated Show resolved Hide resolved
Comment on lines 31 to 33
public getOIDCUser(): Observable<any> {
return from(this.oauthService.loadUserProfile());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Specify a more precise return type than any for getOIDCUser to enhance type safety and code maintainability.

- public getOIDCUser(): Observable<any> {
+ public getOIDCUser(): Observable<UserProfile> { // Assuming UserProfile is the correct type

Committable suggestion was skipped due low confidence.

src/app/services/authentication.service.ts Outdated Show resolved Hide resolved
Comment on lines 6 to 22
export const authGuard: CanActivateFn = () => {

const authService = inject(AuthenticationService);

return authService.authedState.pipe(
take(1), // Otherwise the Observable doesn't complete!
map((isAuthenticated) => {
if (isAuthenticated) {
return true
} else {
authService.authenticate();
return authService.isLoggedIn();
}
})
);

};
Copy link
Contributor

Choose a reason for hiding this comment

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

Simplify the guard logic by removing the unnecessary else clause.

-      } else {
-        authService.authenticate();
-        return authService.isLoggedIn();
-      }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
export const authGuard: CanActivateFn = () => {
const authService = inject(AuthenticationService);
return authService.authedState.pipe(
take(1), // Otherwise the Observable doesn't complete!
map((isAuthenticated) => {
if (isAuthenticated) {
return true
} else {
authService.authenticate();
return authService.isLoggedIn();
}
})
);
};
export const authGuard: CanActivateFn = () => {
const authService = inject(AuthenticationService);
return authService.authedState.pipe(
take(1), // Otherwise the Observable doesn't complete!
map((isAuthenticated) => {
if (isAuthenticated) {
return true
}
authService.authenticate();
return authService.isLoggedIn();
})
);
};

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 2640805 and 16c2825.
Files selected for processing (1)
  • src/app/layout/header/header.component.ts (1 hunks)
Additional Context Used
Biome (1)
src/app/layout/header/header.component.ts (1)

3-4: All these imports are only used as types.

Additional comments not posted (3)
src/app/layout/header/header.component.ts (3)

10-14: Component configuration looks good.

The use of ngSkipHydration is appropriate for performance optimization in specific scenarios. Ensure this aligns with your performance goals.


18-20: Constructor setup is correct.

Proper use of dependency injection for AuthenticationService ensures that the component can utilize authentication functionality effectively.


30-32: Logout method is implemented correctly.

Proper implementation of the logout method using signout from AuthenticationService ensures that users can effectively log out of the application.

Comment on lines 3 to +5
import { LucideAngularModule } from 'lucide-angular';
import { AuthenticationService } from '../../services/authentication.service';
import { CommonModule } from '@angular/common';
Copy link
Contributor

Choose a reason for hiding this comment

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

Review the import usage as they are only used as types.

Consider using TypeScript's import type to explicitly indicate that these imports are only used for type checking. This can help with clarity and potentially optimize bundling processes.

- import { AuthenticationService } from '../../services/authentication.service';
- import { CommonModule } from '@angular/common';
+ import type { AuthenticationService } from '../../services/authentication.service';
+ import type { CommonModule } from '@angular/common';

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
import { LucideAngularModule } from 'lucide-angular';
import { AuthenticationService } from '../../services/authentication.service';
import { CommonModule } from '@angular/common';
import { LucideAngularModule } from 'lucide-angular';
import type { AuthenticationService } from '../../services/authentication.service';
import type { CommonModule } from '@angular/common';

src/app/layout/header/header.component.ts Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 11

Outside diff range and nitpick comments (4)
src/app/pages/server-details/server-details.component.ts (2)

Line range hint 42-42: Specify a more specific type than any for properties and method parameters to improve type safety.

- features: any[] = [];
+ features: Feature[] = [];
- faqs: any[] = [];
+ faqs: FAQ[] = [];
- availabilityDatacenters: any[] = [];
+ availabilityDatacenters: Datacenter[] = [];
- availabilityZones: any[] = [];
+ availabilityZones: Zone[] = [];
- pricesPerZone: any[] = [];
+ pricesPerZone: PriceZone[] = [];
- similarByFamily: Server[] = [];
+ similarByFamily: ServerDetails[] = [];
- similarByPerformance: Server[] = [];
+ similarByPerformance: ServerDetails[] = [];
- openApiJson: any = require('../../../../sdk/openapi.json');
+ openApiJson: OpenApiJson = require('../../../../sdk/openapi.json');
- instanceProperties: any[] = [];
+ instanceProperties: Property[] = [];
- showTooltip(el: any, content: string) {
+ showTooltip(el: HTMLElement, content: string) {
- serverUrl(server: Server): string {
+ serverUrl(server: ServerDetails): string {

Also applies to: 47-47, 49-49, 50-50, 51-51, 53-53, 54-54, 55-55, 60-60, 61-61, 121-121, 122-122, 141-141, 150-150, 152-152


Line range hint 170-175: Prefer for...of loop for better readability and performance.

- this.serverDetails.prices.forEach((price: ServerPricePKs) => {
+ for (const price of this.serverDetails.prices) {
- this.serverDetails.prices.forEach((price: ServerPricePKs) => {
+ for (const price of this.serverDetails.prices) {

Also applies to: 218-230

src/app/pages/server-listing/server-listing.component.ts (2)

Line range hint 337-343: Use template literals for string concatenation to improve readability and maintainability.

- return ((item.server.memory || 0) / 1024).toFixed(1) + ' GB';
+ return `${((item.server.memory || 0) / 1024).toFixed(1)} GB`;

- return ((item.server.gpu_memory_min || 0) / 1024).toFixed(1) + ' GB';
+ return `${((item.server.gpu_memory_min || 0) / 1024).toFixed(1)} GB`;

Line range hint 181-181: The @HostBinding decorator is incorrectly placed or misused here. Ensure it is used correctly or remove it if unnecessary.

- @HostBinding('attr.ngSkipHydration') ngSkipHydration = 'true';
+ // Correct usage or removal of the decorator
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 16c2825 and 223acc6.
Files selected for processing (14)
  • src/app/app.config.ts (2 hunks)
  • src/app/guards/auth.guard.ts (1 hunks)
  • src/app/pages/my-spare-cores/my-spare-cores.component.html (1 hunks)
  • src/app/pages/my-spare-cores/my-spare-cores.component.scss (1 hunks)
  • src/app/pages/my-spare-cores/my-spare-cores.component.ts (1 hunks)
  • src/app/pages/server-details/server-details.component.html (1 hunks)
  • src/app/pages/server-details/server-details.component.ts (5 hunks)
  • src/app/pages/server-listing/server-listing.component.ts (7 hunks)
  • src/app/services/authentication.service.ts (1 hunks)
  • src/app/services/keeper-api.service.ts (2 hunks)
  • src/app/services/my_http/my-http.ts (3 hunks)
  • src/app/services/users-api.service.spec.ts (1 hunks)
  • src/app/services/users-api.service.ts (1 hunks)
  • tailwind.config.js (2 hunks)
Files skipped from review due to trivial changes (1)
  • src/app/services/users-api.service.spec.ts
Files skipped from review as they are similar to previous changes (2)
  • src/app/pages/my-spare-cores/my-spare-cores.component.scss
  • src/app/pages/server-details/server-details.component.html
Additional Context Used
Biome (118)
src/app/app.config.ts (5)

12-12: The computed expression can be simplified without the use of a string literal.


13-13: The computed expression can be simplified without the use of a string literal.


14-14: The computed expression can be simplified without the use of a string literal.


15-15: The computed expression can be simplified without the use of a string literal.


1-1: Some named imports are only used as types.

src/app/guards/auth.guard.ts (2)

15-18: This else clause can be omitted because previous branches break early.


1-1: All these imports are only used as types.

src/app/pages/my-spare-cores/my-spare-cores.component.ts (20)

52-52: Decorators are not valid here.


32-32: Unexpected any. Specify a different type.


39-39: Unexpected any. Specify a different type.


43-43: Unexpected any. Specify a different type.


44-44: Unexpected any. Specify a different type.


45-45: Unexpected any. Specify a different type.


75-75: Unexpected any. Specify a different type.


76-76: Unexpected any. Specify a different type.


102-102: Unexpected any. Specify a different type.


105-105: Unexpected any. Specify a different type.


106-106: Unexpected any. Specify a different type.


112-112: Unexpected any. Specify a different type.


126-126: Unexpected any. Specify a different type.


128-133: Prefer for...of instead of forEach.


137-137: Unexpected any. Specify a different type.


140-144: Prefer for...of instead of forEach.


1-1: Some named imports are only used as types.


1-2: Some named imports are only used as types.


4-5: All these imports are only used as types.


5-6: All these imports are only used as types.

src/app/pages/server-details/server-details.component.ts (20)

130-130: Decorators are not valid here.


42-42: Unexpected any. Specify a different type.


47-47: Unexpected any. Specify a different type.


49-49: Unexpected any. Specify a different type.


50-50: Unexpected any. Specify a different type.


51-51: Unexpected any. Specify a different type.


53-53: Unexpected any. Specify a different type.


54-54: Unexpected any. Specify a different type.


55-55: Unexpected any. Specify a different type.


60-60: Unexpected any. Specify a different type.


61-61: Unexpected any. Specify a different type.


121-121: Unexpected any. Specify a different type.


122-122: Unexpected any. Specify a different type.


141-141: The computed expression can be simplified without the use of a string literal.


142-142: The computed expression can be simplified without the use of a string literal.


150-150: Unexpected any. Specify a different type.


152-152: Template literals are preferred over string concatenation.


170-175: Prefer for...of instead of forEach.


209-209: Template literals are preferred over string concatenation.


218-230: Prefer for...of instead of forEach.

src/app/pages/server-listing/server-listing.component.ts (20)

181-181: Decorators are not valid here.


153-153: Unexpected any. Specify a different type.


155-155: Unexpected any. Specify a different type.


158-158: Unexpected any. Specify a different type.


161-161: Unexpected any. Specify a different type.


162-162: Unexpected any. Specify a different type.


163-163: Unexpected any. Specify a different type.


164-164: Unexpected any. Specify a different type.


166-166: Unexpected any. Specify a different type.


171-171: Unexpected any. Specify a different type.


179-179: Unexpected any. Specify a different type.


199-199: Unexpected any. Specify a different type.


201-201: Unexpected any. Specify a different type.


222-225: Prefer for...of instead of forEach.


252-255: Prefer for...of instead of forEach.


337-339: Template literals are preferred over string concatenation.


341-343: Template literals are preferred over string concatenation.


356-357: Unexpected any. Specify a different type.


363-363: Unexpected any. Specify a different type.


366-367: Unexpected any. Specify a different type.

src/app/services/authentication.service.ts (3)

29-29: Unexpected any. Specify a different type.


75-75: The computed expression can be simplified without the use of a string literal.


1-2: All these imports are only used as types.

src/app/services/keeper-api.service.ts (12)

25-25: Decorators are not valid here.


30-30: Unexpected any. Specify a different type.


34-34: Unexpected any. Specify a different type.


38-38: Unexpected any. Specify a different type.


42-42: Unexpected any. Specify a different type.


46-46: Unexpected any. Specify a different type.


50-50: Unexpected any. Specify a different type.


54-54: Unexpected any. Specify a different type.


58-58: Unexpected any. Specify a different type.


1-1: All these imports are only used as types.


5-6: All these imports are only used as types.


8-9: All these imports are only used as types.

src/app/services/my_http/my-http.ts (15)

20-20: Decorators are not valid here.


11-11: The computed expression can be simplified without the use of a string literal.


12-12: The computed expression can be simplified without the use of a string literal.


24-24: Unexpected any. Specify a different type.


24-24: Unexpected any. Specify a different type.


40-40: Unexpected any. Specify a different type.


45-45: Unexpected any. Specify a different type.


45-45: This type annotation is trivially inferred from its initialization.


45-45: Unexpected any. Specify a different type.


46-46: Unexpected any. Specify a different type.


61-61: Unexpected any. Specify a different type.


66-71: This else clause can be omitted because previous branches break early.


1-2: Some named imports are only used as types.


3-4: Some named imports are only used as types.


5-6: All these imports are only used as types.

src/app/services/users-api.service.ts (18)

15-15: Decorators are not valid here.


20-20: Unexpected any. Specify a different type.


24-26: This else clause can be omitted because previous branches break early.


29-29: Unexpected any. Specify a different type.


35-37: This else clause can be omitted because previous branches break early.


44-44: Unexpected any. Specify a different type.


56-56: Unexpected any. Specify a different type.


60-62: This else clause can be omitted because previous branches break early.


65-65: Unexpected any. Specify a different type.


71-73: This else clause can be omitted because previous branches break early.


76-76: Unexpected any. Specify a different type.


80-82: This else clause can be omitted because previous branches break early.


89-91: This else clause can be omitted because previous branches break early.


1-2: All these imports are only used as types.


4-5: All these imports are only used as types.


43-43: This let declares a variable that is only assigned once.


51-53: This block statement doesn't serve any purpose and can be safely removed.


68-68: This let declares a variable that is only assigned once.

tailwind.config.js (3)

14-14: The computed expression can be simplified without the use of a string literal.


15-15: The computed expression can be simplified without the use of a string literal.


18-18: The computed expression can be simplified without the use of a string literal.

Additional comments not posted (11)
tailwind.config.js (1)

Line range hint 28-45: The Tailwind CSS configuration updates look good.

src/app/services/keeper-api.service.ts (2)

9-9: The import of AuthenticationService is correctly added for user authentication in API calls.


26-26: The constructor correctly initializes AuthenticationService and HttpClient for use in the service.

src/app/services/authentication.service.ts (2)

16-26: The OAuth event handling logic is correctly implemented to update the authentication state based on different events.


33-57: The methods tryAutoLogin and authenticate are well-implemented to support both automatic and explicit authentication flows.

src/app/app.config.ts (1)

17-28: The OAuth configuration settings are correctly set up according to the ZITADEL documentation.

src/app/services/my_http/my-http.ts (2)

19-19: The constructor correctly initializes AuthenticationService and platform ID for use in the custom HTTP client.


36-39: The request method correctly handles authentication tokens and retries, ensuring robust API interactions.

src/app/pages/my-spare-cores/my-spare-cores.component.html (1)

1-151: Ensure correct Angular bindings and HTML structure.

The HTML structure and Angular bindings appear correct and follow best practices for Angular applications.

src/app/pages/server-listing/server-listing.component.ts (2)

15-15: Consider specifying a more explicit type than any for better type safety and to avoid potential runtime errors.

- import { UsersAPIService } from '../../services/users-api.service';
+ import { UsersAPIService, UserData } from '../../services/users-api.service'; // Assuming UserData is the type returned by the service

Likely invalid or redundant comment.


186-187: Ensure proper error handling in asynchronous operations to enhance reliability.

Also applies to: 543-544, 558-559, 566-567, 577-578, 588-589

Comment on lines 15 to 18
} else {
authService.authenticate();
return authService.isLoggedIn();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider simplifying the guard logic by removing the unnecessary else clause.

-      } else {
-        authService.authenticate();
-        return authService.isLoggedIn();
-      }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
} else {
authService.authenticate();
return authService.isLoggedIn();
}

Comment on lines +15 to +17
@Inject(PLATFORM_ID) private platformId: object,
private httpClient: HttpClient,
private auth: AuthenticationService
Copy link
Contributor

Choose a reason for hiding this comment

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

Incorrect usage of decorators in the constructor parameters.

- @Inject(PLATFORM_ID) private platformId: object,
+ private platformId: object,

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
@Inject(PLATFORM_ID) private platformId: object,
private httpClient: HttpClient,
private auth: AuthenticationService
private platformId: object,
private httpClient: HttpClient,
private auth: AuthenticationService

private auth: AuthenticationService
) { }

public getCurrentUserData(): Promise<any> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Specify a more specific type than any for method return types and parameters to improve type safety.

- public getCurrentUserData(): Promise<any> {
+ public getCurrentUserData(): Promise<UserData> {
- public insertOrUpdateUserData(data: any): Promise<void> {
+ public insertOrUpdateUserData(data: UserData): Promise<void> {
- public toggleWatchlist(vendor_id: string, server_id: string): Promise<void> {
+ public toggleWatchlist(vendor_id: string, server_id: string): Promise<Watchlist> {
- public async getWatchlist(): Promise<any> {
+ public async getWatchlist(): Promise<Watchlist[]> {
- public async saveSearchHistory(searchObject: any): Promise<void> {
+ public async saveSearchHistory(searchObject: SearchHistory): Promise<void> {
- public async getSearchHistory(): Promise<any> {
+ public async getSearchHistory(): Promise<SearchHistory[]> {

Also applies to: 29-29, 44-44, 56-56, 65-65, 76-76

Committable suggestion was skipped due low confidence.

public toggleWatchlist(vendor_id: string, server_id: string): Promise<void> {
const userID = this.auth.getUserID();
if(userID) {
let userWatchlist = JSON.parse(localStorage.getItem(`user_watchlist_${userID}`) || '[]');
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid reassigning variables that are only assigned once.

- let userWatchlist = JSON.parse(localStorage.getItem(`user_watchlist_${userID}`) || '[]');
+ const userWatchlist = JSON.parse(localStorage.getItem(`user_watchlist_${userID}`) || '[]');
- let searchHistory = JSON.parse(localStorage.getItem(`search_history_${userID}`) || '[]');
+ const searchHistory = JSON.parse(localStorage.getItem(`search_history_${userID}`) || '[]');

Also applies to: 68-68

Committable suggestion was skipped due low confidence.

Comment on lines +24 to +26
} else {
return Promise.resolve(undefined);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove unnecessary else clauses to simplify the code.

- } else {
-   return Promise.resolve(undefined);
- }
- } else {
-   return Promise.resolve();
- }
- } else {
-   return Promise.resolve([]);
- }
- } else {
-   return Promise.resolve();
- }
- } else {
-   return Promise.resolve([]);
- }
- } else {
-   return Promise.resolve();
- }

Also applies to: 35-37, 60-62, 71-73, 80-82, 89-91

Committable suggestion was skipped due low confidence.

Comment on lines +140 to +144
Object.keys(query).forEach((key) => {
if(Array.isArray(query[key])) {
query[key] = query[key].join(',');
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer for...of loop for better readability and performance.

- Object.keys(query).forEach((key) => {
+ for (const key of Object.keys(query)) {

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
Object.keys(query).forEach((key) => {
if(Array.isArray(query[key])) {
query[key] = query[key].join(',');
}
});
for (const key of Object.keys(query)) {
if(Array.isArray(query[key])) {
query[key] = query[key].join(',');
}
}

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 223acc6 and 4c4eb27.

Files selected for processing (1)
  • src/app/pages/my-spare-cores/my-spare-cores.component.ts (1 hunks)
Additional context used
Biome
src/app/pages/my-spare-cores/my-spare-cores.component.ts

[error] 52-52: Decorators are not valid here.


[error] 32-32: Unexpected any. Specify a different type.


[error] 39-39: Unexpected any. Specify a different type.


[error] 43-43: Unexpected any. Specify a different type.


[error] 44-44: Unexpected any. Specify a different type.


[error] 45-45: Unexpected any. Specify a different type.


[error] 75-75: Unexpected any. Specify a different type.


[error] 76-76: Unexpected any. Specify a different type.


[error] 102-102: Unexpected any. Specify a different type.


[error] 105-105: Unexpected any. Specify a different type.


[error] 106-106: Unexpected any. Specify a different type.


[error] 112-112: Unexpected any. Specify a different type.


[error] 126-126: Unexpected any. Specify a different type.


[error] 128-133: Prefer for...of instead of forEach.


[error] 137-137: Unexpected any. Specify a different type.


[error] 141-145: Prefer for...of instead of forEach.


[error] 1-1: Some named imports are only used as types.


[error] 1-2: Some named imports are only used as types.


[error] 4-5: All these imports are only used as types.


[error] 5-6: All these imports are only used as types.

@ViewChild('tooltipDefault') tooltip!: ElementRef;

constructor(
@Inject(PLATFORM_ID) private platformId: object,
Copy link
Contributor

Choose a reason for hiding this comment

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

Incorrect usage of decorators in constructor parameters.

- @Inject(PLATFORM_ID) private platformId: object,
+ private platformId: object,

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
@Inject(PLATFORM_ID) private platformId: object,
private platformId: object,

{category_id: 'search_history', name: 'Search History', icon: 'search'},
];

searchSettings: any[] = [
Copy link
Contributor

Choose a reason for hiding this comment

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

Specify more specific types than any for properties and method parameters to improve type safety.

- searchSettings: any[] = [
+ searchSettings: SearchSetting[] = [
- servers: any[] = [];
+ servers: Server[] = [];
- userData: any;
+ userData: UserData;
- watchlistItems: any[] = [];
+ watchlistItems: WatchlistItem[] = [];
- searchHistory: any[] = [];
+ searchHistory: SearchHistoryItem[] = [];
- clearWatchlist(item: any) {
+ clearWatchlist(item: WatchlistItem) {
- showTooltip(el: any, content: string) {
+ showTooltip(el: HTMLElement, content: string) {
- getSearchHistoryItemDescription(item: any) {
+ getSearchHistoryItemDescription(item: SearchHistoryItem) {
- openSearchHistoryItem(item: any) {
+ openSearchHistoryItem(item: SearchHistoryItem) {

Also applies to: 39-39, 43-45, 75-76, 102-102, 105-106, 112-112, 126-126, 137-137

Committable suggestion was skipped due low confidence.

Comment on lines +128 to +133
Object.keys(item).forEach((key) => {
if(description.length > 0) {
description += ' | ';
}
description += `${key}: ${item[key]} `;
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer for...of loop for better readability and performance.

- Object.keys(query).forEach((key) => {
+ for (const key of Object.keys(query)) {
- Object.keys(item).forEach((key) => {
+ for (const key of Object.keys(item)) {

Also applies to: 141-145

Committable suggestion was skipped due low confidence.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4c4eb27 and 0d20e1b.

Files selected for processing (2)
  • README.md (1 hunks)
  • src/app/services/authentication.service.ts (1 hunks)
Additional context used
Biome
src/app/services/authentication.service.ts

[error] 29-29: Unexpected any. Specify a different type.


[error] 80-80: The computed expression can be simplified without the use of a string literal.


[error] 1-2: All these imports are only used as types.

Markdownlint
README.md

26-26: null
Bare URL used


33-33: null
Bare URL used


34-34: null
Bare URL used


35-35: null
Bare URL used

if(!this.oauthService.getIdentityClaims()) {
return undefined;
}
return this.oauthService.getIdentityClaims()['sub'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Simplify the computed expression without using a string literal.

- return this.oauthService.getIdentityClaims()['sub'];
+ return this.oauthService.getIdentityClaims().sub;

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
return this.oauthService.getIdentityClaims()['sub'];
return this.oauthService.getIdentityClaims().sub;

});
}

public getOIDCUser(): Promise<any> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Specify a more precise return type than any for getOIDCUser.

- public getOIDCUser(): Promise<any> {
+ public getOIDCUser(): Promise<UserProfile> { // Assuming UserProfile is the correct type

Committable suggestion was skipped due low confidence.

Comment on lines +1 to +2
import { Injectable } from '@angular/core';
import { AuthConfig, OAuthEvent, OAuthService } from 'angular-oauth2-oidc';
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using type-only imports for Angular and RxJS modules.

- import { Injectable } from '@angular/core';
- import { AuthConfig, OAuthEvent, OAuthService } from 'angular-oauth2-oidc';
- import { BehaviorSubject } from 'rxjs';
+ import type { Injectable } from '@angular/core';
+ import type { AuthConfig, OAuthEvent, OAuthService } from 'angular-oauth2-oidc';
+ import type { BehaviorSubject } from 'rxjs';

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
import { Injectable } from '@angular/core';
import { AuthConfig, OAuthEvent, OAuthService } from 'angular-oauth2-oidc';
import type { Injectable } from '@angular/core';
import type { AuthConfig, OAuthEvent, OAuthService } from 'angular-oauth2-oidc';
import type { BehaviorSubject } from 'rxjs';

Set the following environment variables to configure the OIDC provider:

- NG_APP_ZITADEL_CLIENT_ID: The client ID of the OIDC provider e.g. 123456789123456@sc-www
- NG_APP_ZITADEL_DOMAIN: The domain of the OIDC provider e.g. https://YOUR-PROJECT.zitadel.cloud
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid using bare URLs in markdown files.

- - NG_APP_ZITADEL_DOMAIN: The domain of the OIDC provider e.g. https://YOUR-PROJECT.zitadel.cloud
- - NG_APP_ZITADEL_USERINFO_ENDPOINT: The OIDC provider userinfo endpoint e.g. https://YOUR-PROJECT.zitadel.cloud/oidc/v1/userinfo
+ - NG_APP_ZITADEL_DOMAIN: The domain of the OIDC provider, for example, [YOUR-PROJECT ZITADEL](https://YOUR-PROJECT.zitadel.cloud)
+ - NG_APP_ZITADEL_USERINFO_ENDPOINT: The OIDC provider userinfo endpoint, for example, [ZITADEL Userinfo](https://YOUR-PROJECT.zitadel.cloud/oidc/v1/userinfo)

Also applies to: 34-34, 35-35


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- NG_APP_ZITADEL_DOMAIN: The domain of the OIDC provider e.g. https://YOUR-PROJECT.zitadel.cloud
- NG_APP_ZITADEL_DOMAIN: The domain of the OIDC provider, for example, [YOUR-PROJECT ZITADEL](https://YOUR-PROJECT.zitadel.cloud)
- NG_APP_ZITADEL_USERINFO_ENDPOINT: The OIDC provider userinfo endpoint, for example, [ZITADEL Userinfo](https://YOUR-PROJECT.zitadel.cloud/oidc/v1/userinfo)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0d20e1b and 382ca64.

Files selected for processing (2)
  • src/app/guards/auth.guard.ts (1 hunks)
  • src/app/services/authentication.service.ts (1 hunks)
Additional context used
Biome
src/app/guards/auth.guard.ts

[error] 15-18: This else clause can be omitted because previous branches break early.


[error] 16-16: Template literals are preferred over string concatenation.


[error] 1-1: All these imports are only used as types.

src/app/services/authentication.service.ts

[error] 29-29: Unexpected any. Specify a different type.


[error] 80-80: The computed expression can be simplified without the use of a string literal.


[error] 1-2: All these imports are only used as types.

Additional comments not posted (4)
src/app/guards/auth.guard.ts (1)

15-18: Simplify the guard logic by removing the unnecessary else clause.

src/app/services/authentication.service.ts (3)

29-29: Specify a more precise return type than any for getOIDCUser.


80-80: Simplify the computed expression without using a string literal.


1-2: Convert imports to type-only imports to clarify their usage.

if (isAuthenticated) {
return true
} else {
authService.authenticate('/' + route.url.join('/'));
Copy link
Contributor

Choose a reason for hiding this comment

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

Use template literals for path concatenation.

- authService.authenticate('/' +  route.url.join('/'));
+ authService.authenticate(`/${route.url.join('/')}`);

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
authService.authenticate('/' + route.url.join('/'));
authService.authenticate(`/${route.url.join('/')}`);

@@ -0,0 +1,22 @@
import { CanActivateFn } from '@angular/router';
Copy link
Contributor

Choose a reason for hiding this comment

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

Convert imports to type-only imports to clarify their usage.

- import { CanActivateFn } from '@angular/router';
- import { AuthenticationService } from '../services/authentication.service';
+ import type { CanActivateFn } from '@angular/router';
+ import type { AuthenticationService } from '../services/authentication.service';

Committable suggestion was skipped due low confidence.

@daroczig daroczig changed the title Dev 149 zitadel Aug 22, 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.

2 participants