-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* configure eslint
- Loading branch information
Showing
45 changed files
with
2,469 additions
and
300 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,13 +1,14 @@ | ||
import { defineConfig } from 'drizzle-kit'; | ||
import { defineConfig } from 'drizzle-kit' | ||
|
||
export default defineConfig({ | ||
schema: './src/modules/drizzle/schema.ts', | ||
out: './migrations', | ||
dialect: 'mysql', | ||
dialect: 'mysql', | ||
// TODO(lwvemike): take this from configService | ||
dbCredentials: { | ||
host: process.env.DB_HOST, | ||
user: process.env.DB_USER, | ||
password: process.env.DB_PASSWORD, | ||
database: process.env.DB_NAME, | ||
host: process.env.DB_HOST!, | ||
user: process.env.DB_USER!, | ||
password: process.env.DB_PASSWORD!, | ||
database: process.env.DB_NAME!, | ||
}, | ||
}); | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import antfu from '@antfu/eslint-config' | ||
|
||
export default antfu({ | ||
typescript: { | ||
overrides: { | ||
'ts/consistent-type-imports': 'off', | ||
}, | ||
}, | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
TOKEN_PREFIX="keys/$1" | ||
|
||
set -e | ||
|
||
openssl ecparam -name prime256v1 -genkey -noout -out "$TOKEN_PREFIX-priv-key.pem" | ||
openssl ec -in "$TOKEN_PREFIX-priv-key.pem" -pubout > "$TOKEN_PREFIX-pub-key.pem" | ||
|
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 +1 @@ | ||
{"version":"7","dialect":"mysql","entries":[]} | ||
{ "version": "7", "dialect": "mysql", "entries": [] } |
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,13 +1,29 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { AuthenticationModule } from './modules/authentication/authentication.module'; | ||
import { DrizzleModule } from './modules/drizzle/drizzle.module'; | ||
import { ConfigurationModule } from './modules/configuration/configuration.module'; | ||
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common' | ||
import { AuthenticationModule } from './modules/authentication/authentication.module' | ||
import { DrizzleModule } from './modules/drizzle/drizzle.module' | ||
import { ConfigurationModule } from './modules/configuration/configuration.module' | ||
import { ProtectedModule } from './modules/protected/protected.module' | ||
import { SessionMiddleware } from './modules/session/session.middleware' | ||
import { JwtModule } from './modules/jwt/jwt.module' | ||
import { SessionModule } from './modules/session/session.module' | ||
|
||
@Module({ | ||
imports: [ | ||
ConfigurationModule, | ||
DrizzleModule, | ||
AuthenticationModule | ||
JwtModule, | ||
SessionModule, | ||
AuthenticationModule, | ||
ProtectedModule, | ||
], | ||
}) | ||
export class AppModule {} | ||
export class AppModule implements NestModule { | ||
static readonly GLOBAL_PREFIX = '/api' | ||
|
||
configure(consumer: MiddlewareConsumer) { | ||
consumer | ||
.apply(SessionMiddleware) | ||
.exclude(...SessionMiddleware.EXCLUDE_ROUTES) | ||
.forRoutes('*') | ||
} | ||
} |
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,20 +1,22 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import { AppModule } from './app.module'; | ||
import { ConfigModule, ConfigService} from '@nestjs/config'; | ||
import { Config } from './modules/configuration/parse-config'; | ||
import { INestApplication } from '@nestjs/common'; | ||
import { NestFactory } from '@nestjs/core' | ||
import { ConfigService } from '@nestjs/config' | ||
import * as cookieParser from 'cookie-parser' | ||
import type { Config } from './modules/configuration/parse-config' | ||
import { AppModule } from './app.module' | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule); | ||
app.setGlobalPrefix('api'); | ||
const app = await NestFactory.create(AppModule) | ||
app.setGlobalPrefix('/api') | ||
/** | ||
* @description Express is exposing the ip on the request object | ||
*/ | ||
// @ts-expect-error | ||
app.set('trust proxy', true) | ||
|
||
const configService = app.get(ConfigService); | ||
app.use(cookieParser()) | ||
|
||
await app.listen(configService.get<Config['port']>('port')); | ||
const configService = app.get(ConfigService) | ||
|
||
await app.listen(configService.get<Config['port']>('port')!) | ||
} | ||
bootstrap(); | ||
bootstrap() |
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
31 changes: 31 additions & 0 deletions
31
apps/backend/src/modules/authentication/authentication.guard.ts
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { CanActivate, ExecutionContext } from '@nestjs/common' | ||
import { Injectable, Logger } from '@nestjs/common' | ||
import type { Observable } from 'rxjs' | ||
import { z } from 'zod' | ||
import { SessionService } from '../session/session.service' | ||
import { JwtService } from '../jwt/jwt.service' | ||
|
||
@Injectable() | ||
export class AuthenticationGuard implements CanActivate { | ||
readonly #logger = new Logger(AuthenticationGuard.name) | ||
constructor( | ||
private readonly sessionService: SessionService, | ||
) { } | ||
|
||
canActivate( | ||
context: ExecutionContext, | ||
): boolean | Promise<boolean> | Observable<boolean> { | ||
const request = context.switchToHttp().getRequest() | ||
|
||
const result = z.string().safeParse(request.cookies?.[JwtService.ACCESS_TOKEN_NAME]) | ||
|
||
if (result.success === false) { | ||
this.#logger.error('No token found in request') | ||
return false | ||
} | ||
|
||
const { data: token } = result | ||
|
||
return this.sessionService.tieSession(token) | ||
} | ||
} |
13 changes: 7 additions & 6 deletions
13
apps/backend/src/modules/authentication/authentication.module.ts
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
Oops, something went wrong.