From a85394ac9db5a256934eba9eb260c7e8d0fc692a Mon Sep 17 00:00:00 2001 From: Adelina Enache Date: Wed, 12 Jun 2024 18:13:39 +0300 Subject: [PATCH 1/5] fix(apple): use display name (#111) * fix apple callback endpoint http verb * add a get requst for apple aswell From f8e7b4d0c2eb9c93af58457445a1bc1d84535e14 Mon Sep 17 00:00:00 2001 From: rajdip-b Date: Wed, 12 Jun 2024 21:56:16 +0530 Subject: [PATCH 2/5] chore(fly): Update fly config --- .github/workflows/deploy.yml | 3 ++- fly.prod.toml | 33 +++++++++++++++++++++++++++++++++ fly.toml => fly.stage.toml | 4 ++-- 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 fly.prod.toml rename fly.toml => fly.stage.toml (90%) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5be9daf..42debfb 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -42,9 +42,10 @@ jobs: - name: Deploy env: FLY_APP_NAME: ${{ vars.FLY_APP_NAME }} + FLY_CONFIG_FILE_NAME: ${{ github.ref == 'refs/heads/main' && 'fly.prod.toml' || 'flu.stage.toml' }} run: | ~/.fly/bin/fly deploy \ - --config fly.toml \ + --config $FLY_CONFIG_FILE_NAME \ --dockerfile Dockerfile \ --app $FLY_APP_NAME \ --access-token $FLY_ACCESS_TOKEN diff --git a/fly.prod.toml b/fly.prod.toml new file mode 100644 index 0000000..31dc8d9 --- /dev/null +++ b/fly.prod.toml @@ -0,0 +1,33 @@ +primary_region = "syd" + +[http_service] + internal_port = 4200 + force_https = true + auto_stop_machines = false + auto_start_machines = false + min_machines_running = 1 + [http_service.concurrency] + type = "requests" + soft_limit = 500 + hard_limit = 750 + +[http_service.tls_options] + alpn = ["h2", "http/1.1"] + versions = ["TLSv1.2", "TLSv1.3"] + default_self_signed = true + +[[http_service.checks]] + grace_period = "10s" + interval = "30s" + method = "GET" + timeout = "10s" + path = "/api/health" + protocol = "http" + port = 4200 + tls_skip_verify = true + +[[vm]] + size = "shared-cpu-1x" + memory = "512mb" + cpus = 1 + cpu_kind = "shared" diff --git a/fly.toml b/fly.stage.toml similarity index 90% rename from fly.toml rename to fly.stage.toml index fbaf08f..cc532d5 100644 --- a/fly.toml +++ b/fly.stage.toml @@ -3,8 +3,8 @@ primary_region = "syd" [http_service] internal_port = 4200 force_https = true - auto_stop_machines = false - auto_start_machines = false + auto_stop_machines = true + auto_start_machines = true min_machines_running = 0 [http_service.concurrency] type = "requests" From 87b011e905ece97300cc08bb0aceded1ad33164f Mon Sep 17 00:00:00 2001 From: Adelina Enache Date: Thu, 13 Jun 2024 14:34:41 +0300 Subject: [PATCH 3/5] fix(socials): resolve redis session issue (#112) * use redis as a store for sessions * fix path for tests * fix tests --- package.json | 1 + pnpm-lock.yaml | 13 +++++++++++++ src/app/app.module.ts | 20 ++++++++++++++++++-- src/auth/service/auth.service.ts | 4 ++-- src/main.ts | 2 -- 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index dac540e..a077bcf 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "cheerio": "1.0.0-rc.12", "class-transformer": "^0.5.1", "class-validator": "^0.14.1", + "connect-redis": "^7.1.1", "crypto-js": "^4.2.0", "expo-server-sdk": "^3.10.0", "express": "^4.19.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 42c4f94..217cb90 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -65,6 +65,9 @@ importers: class-validator: specifier: ^0.14.1 version: 0.14.1 + connect-redis: + specifier: ^7.1.1 + version: 7.1.1(express-session@1.18.0) crypto-js: specifier: ^4.2.0 version: 4.2.0 @@ -1761,6 +1764,12 @@ packages: resolution: {integrity: sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==} engines: {'0': node >= 0.8} + connect-redis@7.1.1: + resolution: {integrity: sha512-M+z7alnCJiuzKa8/1qAYdGUXHYfDnLolOGAUjOioB07pP39qxjG+X9ibsud7qUBc4jMV5Mcy3ugGv8eFcgamJQ==} + engines: {node: '>=16'} + peerDependencies: + express-session: '>=1' + consola@2.15.3: resolution: {integrity: sha512-9vAdYbHj6x2fLKC4+oPH0kFzY/orMZyG2Aj+kNylHxKGJ/Ed4dpNyAQYwJOdqO4zdM7XpVHmyejQDcQHrnuXbw==} @@ -6334,6 +6343,10 @@ snapshots: readable-stream: 2.3.8 typedarray: 0.0.6 + connect-redis@7.1.1(express-session@1.18.0): + dependencies: + express-session: 1.18.0 + consola@2.15.3: {} content-disposition@0.5.4: diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 6462bc0..e1e08ec 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,4 +1,4 @@ -import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common'; +import { Inject, MiddlewareConsumer, Module, NestModule } from '@nestjs/common'; import { AppController } from './app.controller'; import { AuthModule } from '../auth/auth.module'; import { UserModule } from '../user/user.module'; @@ -14,6 +14,10 @@ import { ConnectionsModule } from '../../src/connections/connections.module'; import { AppLoggerMiddleware } from '../../src/middlewares/logger.middleware'; import { CommonModule } from '../common/common.module'; import { NotificationsModule } from '../../src/notifications/notifications.module'; +import RedisStore from 'connect-redis'; +import * as session from 'express-session'; +import Redis from 'ioredis'; +import { REDIS_CLIENT } from '../../src/provider/redis.provider'; @Module({ imports: [ @@ -40,7 +44,19 @@ import { NotificationsModule } from '../../src/notifications/notifications.modul ], }) export class AppModule implements NestModule { + constructor(@Inject(REDIS_CLIENT) private redis: Redis) {} + configure(consumer: MiddlewareConsumer): void { - consumer.apply(AppLoggerMiddleware).forRoutes('*'); + consumer + .apply( + AppLoggerMiddleware, + session({ + secret: process.env.SESSION_SECRET || 'lala', + resave: false, + saveUninitialized: false, + store: new RedisStore({ client: this.redis }), + }), + ) + .forRoutes('*'); } } diff --git a/src/auth/service/auth.service.ts b/src/auth/service/auth.service.ts index 6464b99..b06effa 100644 --- a/src/auth/service/auth.service.ts +++ b/src/auth/service/auth.service.ts @@ -155,13 +155,13 @@ export class AuthService { } async handleAppleOAuthLogin(req: any) { - const { email, name } = req.user; - const displayName = name.firstName + ' ' + name.lastName; + const { email, displayName } = req.user; const user = await this.createUserIfNotExists( email, AuthType.APPLE, displayName, null, + false, ); const token = await this.generateToken(user); diff --git a/src/main.ts b/src/main.ts index 7d3e2b8..b4894c8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,7 +3,6 @@ import { AppModule } from './app/app.module'; import { ValidationPipe } from '@nestjs/common'; import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; import { json } from 'express'; -import * as session from 'express-session'; function initializeSwagger(app: any) { const config = new DocumentBuilder() @@ -19,7 +18,6 @@ function initializeSwagger(app: any) { async function bootstrap() { const app = await NestFactory.create(AppModule); const globalPrefix = 'api'; - app.use(session({ secret: process.env.SESSION_SECRET })); app.setGlobalPrefix(globalPrefix); app.enableCors(); From ada96a9b35ce1e0c1791a79f5ba345689552e2d8 Mon Sep 17 00:00:00 2001 From: Adelina Enache Date: Thu, 13 Jun 2024 14:51:43 +0300 Subject: [PATCH 4/5] fix(apple): replace backspaces (#114) --- src/oauth/factory/apple/apple-strategy.factory.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/oauth/factory/apple/apple-strategy.factory.ts b/src/oauth/factory/apple/apple-strategy.factory.ts index 75e7526..c6f561f 100644 --- a/src/oauth/factory/apple/apple-strategy.factory.ts +++ b/src/oauth/factory/apple/apple-strategy.factory.ts @@ -15,7 +15,9 @@ export class AppleOAuthStrategyFactory implements OAuthStrategyFactory { this.clientID = this.configService.get('APPLE_CLIENT_ID'); this.teamID = this.configService.get('APPLE_TEAM_ID'); this.keyID = this.configService.get('APPLE_KEY_ID'); - this.key = this.configService.get('APPLE_KEY'); + this.key = this.configService + .get('APPLE_KEY') + .replace(/\\n/gm, '\n'); this.callbackURL = this.configService.get('APPLE_CALLBACK_URL'); } From e3b77ee6cc2fdd9fe8f08833c4190a2c8d9bf17e Mon Sep 17 00:00:00 2001 From: Adelina Enache Date: Thu, 13 Jun 2024 15:19:50 +0300 Subject: [PATCH 5/5] fix(apple): tests (#115) * fix(apple): replace backspaces * fix(apple): tests --- src/oauth/factory/apple/apple-strategy.factory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/oauth/factory/apple/apple-strategy.factory.ts b/src/oauth/factory/apple/apple-strategy.factory.ts index c6f561f..afe9f80 100644 --- a/src/oauth/factory/apple/apple-strategy.factory.ts +++ b/src/oauth/factory/apple/apple-strategy.factory.ts @@ -17,7 +17,7 @@ export class AppleOAuthStrategyFactory implements OAuthStrategyFactory { this.keyID = this.configService.get('APPLE_KEY_ID'); this.key = this.configService .get('APPLE_KEY') - .replace(/\\n/gm, '\n'); + ?.replace(/\\n/gm, '\n'); this.callbackURL = this.configService.get('APPLE_CALLBACK_URL'); }