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

refactor(api-service): API auth exclusively in API service; cleanup WIP #7640

Draft
wants to merge 2 commits into
base: next
Choose a base branch
from

Conversation

ChmaraX
Copy link
Contributor

@ChmaraX ChmaraX commented Jan 31, 2025

What changed? Why was the change needed?

Screenshots

Expand for optional sections

Related enterprise PR

Special notes for your reviewer

Copy link

netlify bot commented Jan 31, 2025

Deploy Preview for dev-web-novu ready!

Name Link
🔨 Latest commit 64e2241
🔍 Latest deploy log https://app.netlify.com/sites/dev-web-novu/deploys/679e4ef3358bae0008bfda19
😎 Deploy Preview https://deploy-preview-7640.dashboard.novu-staging.co
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Jan 31, 2025

Deploy Preview for dashboard-v2-novu-staging ready!

Name Link
🔨 Latest commit 64e2241
🔍 Latest deploy log https://app.netlify.com/sites/dashboard-v2-novu-staging/deploys/679e4ef3477ce10008b5a997
😎 Deploy Preview https://deploy-preview-7640.dashboard-v2.novu-staging.co
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines +43 to +47
import { SwitchEnvironmentCommand } from './usecases/switch-environment/switch-environment.command';
import { SwitchEnvironment } from './usecases/switch-environment/switch-environment.usecase';
import { SwitchOrganizationCommand } from './usecases/switch-organization/switch-organization.command';
import { SwitchOrganization } from './usecases/switch-organization/switch-organization.usecase';
import { AuthService } from './services/auth.service';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These services are used only in API, no reason to have them in app-generic


@Injectable()
export class RootEnvironmentGuard implements CanActivate {
constructor(@Inject(forwardRef(() => AuthService)) private authService: AuthService) {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need to use this magic if it lives in the same package

} from '@novu/shared';
import { IAuthService } from './auth.service.interface';
import { AuthProviderEnum, AuthenticateContext, ISubscriberJwt, UserSessionData } from '@novu/shared';
import { IAuthService } from '@novu/application-generic';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one interface needs to stay in app-generic because its reused in EE auth.

We need to have common auth interface for private and public authentication so it makes sense.

@@ -90,7 +89,6 @@ export class WorkflowController {
}

@Put(':workflowId/sync')
@UseGuards(UserAuthGuard)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there is a @UserAuthentication() on top of controller, doing @UseGuards(UserAuthGuard) on each method is redundant, because @UserAuthentication() already contains that guard inside it

@@ -16,6 +16,7 @@
"@handlebars/parser": "^2.1.0",
"@novu/application-generic": "workspace:*",
"@novu/ee-dal": "workspace:*",
"@novu/ee-auth": "workspace:*",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@novu/ee-translation should use authentication mechanisms directly from @novu/ee-auth package same as @novu/ee-billing

@novu/ee-translation will always be imported only in enterprise mode, why using UserAuthGuard, which insides decides conditionally between EEUserAuthGuard and CommunityUserAuthGuard, when you always know it will be EEUserAuthGuard


@Controller('/bridge')
@UseInterceptors(ClassSerializerInterceptor)
@UserAuthentication()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is equal when used on top of controller
@UserAuthGuard() === @UserAuthentication()
which is equal to using @UseGuards(UserAuthGuard) on each controller method

I used @UserAuthentication() because its used already on 80% of controllers, whereas @UserAuthGuard() was used on the rest 20%

@ChmaraX ChmaraX changed the title refactor(api-service): move API auth exclusively to API service WIP refactor(api-service): API auth exclusively in API service; cleanup WIP Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant