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

feat(session-management): WRK-11 Session management #6 #30

Merged
merged 50 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
64e58c6
refact(security/auth-module): removing tokens, password, and password…
Krr0ptioN Sep 14, 2024
3a5edd0
feat(security/password-module): password service, otpcode and dto val…
Krr0ptioN Sep 14, 2024
6723e6f
feat(security/password-reset-module): sepcial jwt-payload, services, …
Krr0ptioN Sep 14, 2024
da8b0d5
feat(security/tokens-module): generic token module to provide token v…
Krr0ptioN Sep 14, 2024
45310ff
refact(core/users): dto validation for username in decorator moved to…
Krr0ptioN Sep 14, 2024
5181084
feat(common-lib): extracting user agent from request in nestjs contro…
Krr0ptioN Sep 14, 2024
4bded8c
refact(common-lib): optional value type to make drizzle typing and do…
Krr0ptioN Sep 14, 2024
5983a37
feat(security/sessions-module): drizzle data access table for sessions
Krr0ptioN Sep 14, 2024
71aa46b
feat(security/sessions-module): token generation for user authentication
Krr0ptioN Sep 14, 2024
2f972db
feat(security/sessions-module): domain and application layer
Krr0ptioN Sep 14, 2024
e1bc427
feat(ip-detector-lib): geolocation and ip intelligence library to ide…
Krr0ptioN Sep 14, 2024
2c0380e
feat(device-detection-lib): detecting client device informatoin from …
Krr0ptioN Sep 14, 2024
89baa53
refact(users): moving users to core from domain
Krr0ptioN Sep 14, 2024
cacaeb1
chore(types-lib): removing uncessary types lib
Krr0ptioN Sep 14, 2024
9026918
chore(tsconfig): module imports path update
Krr0ptioN Sep 14, 2024
7af922d
chore(ip-locator-device-detection): provding deps for iplocator and d…
Krr0ptioN Sep 14, 2024
3d5beb9
refact(security/tokens-cache): removing caching logic ports
Krr0ptioN Sep 15, 2024
246224d
refact(security/tokens-cache): removing token revoking logic since it…
Krr0ptioN Sep 15, 2024
0611246
fix(security/tokens-cache): adaptingg exception base instead of error
Krr0ptioN Sep 15, 2024
61eb8f0
feat(security/sessions): errors related to session management
Krr0ptioN Sep 15, 2024
3cc1123
chore: export session status type
Krr0ptioN Sep 15, 2024
babd84e
refact(security/sessions): seperating write and model for sessions re…
Krr0ptioN Sep 15, 2024
cccc59f
refact(security/sessions): access token generation using the refresh …
Krr0ptioN Sep 15, 2024
3c56012
feat(security/sessions): session creation, revoking, query actives se…
Krr0ptioN Sep 15, 2024
8f52fcd
refact(security): using options to configure the security modules
Krr0ptioN Sep 15, 2024
70bafb5
chore(security/password): adding bearl file
Krr0ptioN Sep 15, 2024
df95367
refact(security/password): global password module
Krr0ptioN Sep 15, 2024
2543789
fix(security/password-reset): circular imports due to bearl file
Krr0ptioN Sep 15, 2024
d6b484c
fix(security/authentication): circular imports due to bearl file
Krr0ptioN Sep 15, 2024
68bbd58
refact(security/authentication): removing imports and utilizing globa…
Krr0ptioN Sep 15, 2024
6e4973d
refact(security/authentication): using the new sessions revoking serv…
Krr0ptioN Sep 15, 2024
a523879
chore(security/password-reset): adding command handlers, repositories…
Krr0ptioN Sep 15, 2024
295d136
fix(users): making users module global while utilizing global command…
Krr0ptioN Sep 15, 2024
50f50a3
chore: linting
Krr0ptioN Sep 15, 2024
1a211d3
fix(drizzle-missing-columns): strict null check to fix the typescript…
Krr0ptioN Sep 15, 2024
23421e3
chore(banner): print app and docs link with the banner
Krr0ptioN Sep 15, 2024
3c70042
feat(security): sessions options and security module configuration
Krr0ptioN Sep 15, 2024
e33d6a1
feat(security/sessions): refresh access token controller
Krr0ptioN Sep 16, 2024
417ef0b
feat(security/sessions): session management controller
Krr0ptioN Sep 16, 2024
01ac705
feat(security/sessions): repository supports finding sessions based o…
Krr0ptioN Sep 16, 2024
209f5bc
feat(security/sessions): revoke session by id
Krr0ptioN Sep 16, 2024
e683caa
refact(mail): move it to generics
Krr0ptioN Sep 16, 2024
a3cdbcc
refact(config): move it to shared
Krr0ptioN Sep 16, 2024
d53b7b6
chore: add nestjs-pino and pino logger
Krr0ptioN Sep 18, 2024
245fde3
chore: ignore install state of yarn
Krr0ptioN Sep 18, 2024
24cf4cf
chore: merge updates
Krr0ptioN Sep 18, 2024
333282f
chore: changing names for sign up and sign in
Krr0ptioN Sep 18, 2024
b94a782
feat(security/auth-sessions): sign-out and jwt strategy and session api
Krr0ptioN Sep 18, 2024
b99bf5f
feat(api): pretty logging using pino
Krr0ptioN Sep 18, 2024
370d90d
feat(exception-handling): client output
Krr0ptioN Sep 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ infra/postgres
.next
out
.yarn/install-state.gz
.yarn
.yarn/install-state.gz
Binary file removed .yarn/install-state.gz
Binary file not shown.
19 changes: 13 additions & 6 deletions apps/api/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import { ApplicationBootstrapOptions } from '../bootstrap';
import 'dotenv/config';

export default (): ApplicationBootstrapOptions => ({
port: parseInt(process.env[CONFIG_APP.SERVER_PORT]) || 3000,
port: parseInt(process.env[CONFIG_APP.SERVER_PORT]!) || 3000,
security: {
expiresIn: process.env[CONFIG_APP.SECURITY_EXPIRES_IN]!,
refreshIn: process.env[CONFIG_APP.SECURITY_REFRESH_IN]!,
bcryptSalt: process.env[CONFIG_APP.SECURITY_BCRYPT_SALT]!,
jwtRefreshSecret: process.env[CONFIG_APP.JWT_ACCESS_SECRET]!,
jwtAccessSecret: process.env[CONFIG_APP.JWT_REFRESH_SECRET]!,
},
mail: {
provider: process.env[CONFIG_APP.MAIL_INFRA] as MailInfraProvider,
options: {
Expand All @@ -20,10 +27,10 @@ export default (): ApplicationBootstrapOptions => ({
} as MailInfraProviderOptions,
},
database: {
host: process.env[CONFIG_APP.DB_HOST],
port: Number.parseInt(process.env[CONFIG_APP.DB_PORT]),
database: process.env[CONFIG_APP.DB_DATABASE],
user: process.env[CONFIG_APP.DB_USER],
password: process.env[CONFIG_APP.DB_PASSWORD],
host: process.env[CONFIG_APP.DB_HOST]!,
port: Number.parseInt(process.env[CONFIG_APP.DB_PORT]!),
database: process.env[CONFIG_APP.DB_DATABASE]!,
user: process.env[CONFIG_APP.DB_USER]!,
password: process.env[CONFIG_APP.DB_PASSWORD]!,
},
});
58 changes: 49 additions & 9 deletions apps/api/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,73 @@
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { configSchema } from '@goran/config';
import { ApplicationBootstrapOptions } from '../bootstrap';
import { UsersModule } from '@goran/users';
import { AuthenticationModule } from '@goran/security';
import {
AuthenticationModule,
PasswordResetModule,
SessionsModule,
TokensModule,
PasswordModule,
} from '@goran/security';
import { DatabaseModule } from '@goran/drizzle-data-access';
import { MailModule } from '@goran/mail';
import { DeviceDetectorModule } from '@goran/device-detector';
import { IpLocatorModule } from '@goran/ip-locator';
import { CacheModule } from '@nestjs/cache-manager';
import { JwtModule } from '@nestjs/jwt';
import { CqrsModule } from '@nestjs/cqrs';
import { LoggerModule } from 'nestjs-pino';
import { PassportModule } from '@nestjs/passport';

@Module({
imports: [ConfigModule],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {
static register(options: ApplicationBootstrapOptions) {
return {
module: AppModule,
controllers: [AppController],
providers: [AppService],
imports: [
LoggerModule.forRoot({
pinoHttp: {
customProps: (req, res) => ({
context: 'HTTP',
}),
transport: {
target: 'pino-pretty',
options: {
singleLine: true,
},
},
},
}),
CqrsModule.forRoot(),
ConfigModule.forRoot({
isGlobal: true,
envFilePath: ['.env', '.env.local'],
validationSchema: configSchema,
}),
UsersModule,
AuthenticationModule,
CacheModule.register({ isGlobal: true }),
DatabaseModule.forRoot(options.database),
MailModule.register(options.mail),
JwtModule.register({
global: true,
secret: options.security.jwtAccessSecret,
signOptions: {
expiresIn: options.security.expiresIn,
},
}),
PassportModule.register({ global: true }),
UsersModule,
PasswordModule,
TokensModule,
IpLocatorModule,
DeviceDetectorModule,
SessionsModule.register({
refreshIn: options.security.refreshIn,
}),
AuthenticationModule,
PasswordResetModule,
],
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { DatabaseOptions } from '@goran/drizzle-data-access';
import { MailOptions } from '@goran/mail';
import { SecurityOptions } from '@goran/security';

export interface ApplicationBootstrapOptions {
port: number;
security: SecurityOptions;
mail: MailOptions;
database: DatabaseOptions;
}
11 changes: 7 additions & 4 deletions apps/api/src/bootstrap/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@ import {
} from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import cookieParser from 'cookie-parser';
import { Logger, LoggerErrorInterceptor } from 'nestjs-pino';

/**
* Registers global pipes and interceptors, plus server conifguration
*
* @param app - Nestjs application object
* @returns Modified and configured nestjs application object and certain parameters
*/
export async function registerGlobals(app: INestApplication) {
const globalPrefix = 'api';
export async function registerGlobals(
app: INestApplication,
globalPrefix: string
) {
app.enableCors();
app.setGlobalPrefix(globalPrefix);
app.use(cookieParser());
app.useGlobalPipes(new ValidationPipe());
app.useLogger(app.get(Logger));
app.useGlobalInterceptors(new LoggerErrorInterceptor());
app.useGlobalInterceptors(
new ClassSerializerInterceptor(app.get(Reflector))
);

return { app, globalPrefix };
}
25 changes: 13 additions & 12 deletions apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@ import appConfig from './app/app.config';

async function bootstrap() {
const logger = new Logger('BOOTSTRAP');

logger.log(goranBanner);

const config = appConfig();
const app = await NestFactory.create(AppModule.register(config));
const globalPrefix = 'api';
const port = process.env[CONFIG_APP.SERVER_PORT] || 3000;
const { globalPrefix } = await registerGlobals(app);

setupSwagger(app);
const config = appConfig();

logger.log(
` Application is running on: http://localhost:${config.port}/${globalPrefix}`
);
logger.log(
` Documentation is running on: http://localhost:${config.port}/docs`
goranBanner({
appLink: `http://localhost:${config.port}/${globalPrefix}`,
docsLink: `http://localhost:${config.port}/docs`,
})
);

const app = await NestFactory.create(AppModule.register(config), {
bufferLogs: true,
});
await registerGlobals(app, globalPrefix);

setupSwagger(app);

await app.listen(port);
}

Expand Down
18 changes: 0 additions & 18 deletions libs/core/config/.eslintrc.json

This file was deleted.

9 changes: 0 additions & 9 deletions libs/core/config/project.json

This file was deleted.

19 changes: 0 additions & 19 deletions libs/core/config/tsconfig.json

This file was deleted.

10 changes: 0 additions & 10 deletions libs/core/config/tsconfig.lib.json

This file was deleted.

18 changes: 0 additions & 18 deletions libs/core/mail/.eslintrc.json

This file was deleted.

12 changes: 0 additions & 12 deletions libs/core/mail/jest.config.ts

This file was deleted.

9 changes: 0 additions & 9 deletions libs/core/mail/project.json

This file was deleted.

22 changes: 0 additions & 22 deletions libs/core/mail/tsconfig.json

This file was deleted.

16 changes: 0 additions & 16 deletions libs/core/mail/tsconfig.lib.json

This file was deleted.

14 changes: 0 additions & 14 deletions libs/core/mail/tsconfig.spec.json

This file was deleted.

7 changes: 5 additions & 2 deletions libs/core/security/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# security
# @goran/security

This library was generated with [Nx](https://nx.dev).
- Session Management
- SecurityMetrics
- Password Reset
- Authentication

## Running unit tests

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export * from './request-password-reset';
export * from './verify-password-reset-attempt';
export * from './reset-password';
export * from './signup';
export * from './signin';
export * from './sign-up';
export * from './sign-in';
export * from './sign-out';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './sign-in.command-handler';
export * from './sign-in.command';
Loading
Loading