-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ee-auth): Use clerk in the enterprise version (#5755)
- Loading branch information
Showing
128 changed files
with
4,786 additions
and
2,089 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule .source
updated
from 97fae6 to 51c9b1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,24 @@ | ||
import { MiddlewareConsumer, Module, NestModule, Provider, RequestMethod } from '@nestjs/common'; | ||
import { JwtModule } from '@nestjs/jwt'; | ||
import { PassportModule } from '@nestjs/passport'; | ||
const passport = require('passport'); | ||
import { Global, MiddlewareConsumer, Module, ModuleMetadata } from '@nestjs/common'; | ||
import { isClerkEnabled } from '@novu/shared'; | ||
import { getCommunityAuthModuleConfig, configure as configureCommunity } from './community.auth.module.config'; | ||
import { getEEModuleConfig, configure as configureEE } from './ee.auth.module.config'; | ||
|
||
import { AuthProviderEnum, PassportStrategyEnum } from '@novu/shared'; | ||
import { AuthService } from '@novu/application-generic'; | ||
|
||
import { RolesGuard } from './framework/roles.guard'; | ||
import { JwtStrategy } from './services/passport/jwt.strategy'; | ||
import { AuthController } from './auth.controller'; | ||
import { UserModule } from '../user/user.module'; | ||
import { USE_CASES } from './usecases'; | ||
import { SharedModule } from '../shared/shared.module'; | ||
import { GitHubStrategy } from './services/passport/github.strategy'; | ||
import { OrganizationModule } from '../organization/organization.module'; | ||
import { EnvironmentsModule } from '../environments/environments.module'; | ||
import { JwtSubscriberStrategy } from './services/passport/subscriber-jwt.strategy'; | ||
import { UserAuthGuard } from './framework/user.auth.guard'; | ||
import { RootEnvironmentGuard } from './framework/root-environment-guard.service'; | ||
import { ApiKeyStrategy } from './services/passport/apikey.strategy'; | ||
|
||
const AUTH_STRATEGIES: Provider[] = [JwtStrategy, ApiKeyStrategy, JwtSubscriberStrategy]; | ||
|
||
if (process.env.GITHUB_OAUTH_CLIENT_ID) { | ||
AUTH_STRATEGIES.push(GitHubStrategy); | ||
function getModuleConfig(): ModuleMetadata { | ||
if (isClerkEnabled()) { | ||
return getEEModuleConfig(); | ||
} else { | ||
return getCommunityAuthModuleConfig(); | ||
} | ||
} | ||
|
||
@Module({ | ||
imports: [ | ||
OrganizationModule, | ||
SharedModule, | ||
UserModule, | ||
PassportModule.register({ | ||
defaultStrategy: PassportStrategyEnum.JWT, | ||
}), | ||
JwtModule.register({ | ||
secretOrKeyProvider: () => process.env.JWT_SECRET as string, | ||
signOptions: { | ||
expiresIn: 360000, | ||
}, | ||
}), | ||
EnvironmentsModule, | ||
], | ||
controllers: [AuthController], | ||
providers: [UserAuthGuard, ...USE_CASES, ...AUTH_STRATEGIES, AuthService, RolesGuard, RootEnvironmentGuard], | ||
exports: [RolesGuard, RootEnvironmentGuard, AuthService, ...USE_CASES, UserAuthGuard], | ||
}) | ||
export class AuthModule implements NestModule { | ||
@Global() | ||
@Module(getModuleConfig()) | ||
export class AuthModule { | ||
public configure(consumer: MiddlewareConsumer) { | ||
if (process.env.GITHUB_OAUTH_CLIENT_ID) { | ||
consumer | ||
.apply( | ||
passport.authenticate(AuthProviderEnum.GITHUB, { | ||
session: false, | ||
scope: ['user:email'], | ||
}) | ||
) | ||
.forRoutes({ | ||
path: '/auth/github', | ||
method: RequestMethod.GET, | ||
}); | ||
if (isClerkEnabled()) { | ||
configureEE(consumer); | ||
} else { | ||
configureCommunity(consumer); | ||
} | ||
} | ||
} |
Oops, something went wrong.