Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
870b21e
Updated dependencies
bhalperin Jul 10, 2025
a9378ad
Updated nx.json
bhalperin Jul 10, 2025
d6d5991
Created libraries: auth, config, prisma, users
bhalperin Jul 10, 2025
1c8f321
Removed from app code refactored to libraries
bhalperin Jul 10, 2025
c36eed0
Updated eslint and ts configuration files to reference the new libraries
bhalperin Jul 10, 2025
b462dac
CI: updated path to Prisma schema for generating Prisma client
bhalperin Jul 10, 2025
aa29c15
Updated dependencies
bhalperin Jul 22, 2025
5b53291
Updated eslint config files
bhalperin Jul 22, 2025
65ceb23
Updated yarn lock file
bhalperin Jul 22, 2025
6fe8830
Updated dependencies
bhalperin Jul 22, 2025
1ece614
Added prisma lib prebuild script
bhalperin Jul 22, 2025
b8167e0
Added prisma lib prebuild script to prisma lib project file
bhalperin Jul 22, 2025
dc243b9
Updated dependencies
bhalperin Jul 24, 2025
9547681
Updated yarn scripts
bhalperin Jul 24, 2025
1f86418
Added ts compiler option "esModuleInterop": true
bhalperin Jul 24, 2025
f01204b
New copy-files-from-to configuration file - to copy prisma client gen…
bhalperin Jul 24, 2025
323e120
Updated package names and tsconfig paths accordingly
bhalperin Jul 24, 2025
7f16a03
Updated scope dependencies
bhalperin Jul 24, 2025
43cbc0e
Composed prisma lib build targets to include the copying of prisma cl…
bhalperin Jul 24, 2025
4b26a79
Added --verbose flag to nx tasks in CI
bhalperin Jul 24, 2025
100260d
Updated dependencies
bhalperin Jul 25, 2025
07b2e6b
Added prisma prebuild target (an attempt to resolve ci failure)
bhalperin Jul 25, 2025
462c67f
Updated yarn.lock
bhalperin Jul 25, 2025
3292225
Added Prisma client generated code
bhalperin Jul 25, 2025
8ec1668
Updated .gitgnore to include Prisma client generated code
bhalperin Jul 25, 2025
7268e90
Added CI step to list the generated Prisma client code after generation
bhalperin Jul 25, 2025
878a783
Added the generated Prisma client code to the compiler include list
bhalperin Jul 25, 2025
3864da1
Added explicit compilation of generated Prisma client code
bhalperin Jul 25, 2025
a751dea
Reversed the order of files to compile, to make sure generated code c…
bhalperin Jul 25, 2025
d5f6c8a
Removed "outDir"
bhalperin Jul 25, 2025
fcf518d
Created new tsconfig file to compile generated code only
bhalperin Jul 25, 2025
066039d
Removed prisma library prebuild target
bhalperin Jul 25, 2025
cde5988
Ignore (again) generated Prisma client code
bhalperin Jul 25, 2025
d9ceffa
Updated dependencies
bhalperin Jul 26, 2025
ac42fb1
Restored "outDir" tsconfig property
bhalperin Jul 26, 2025
d9aee65
Fixed Import from...
bhalperin Jul 26, 2025
291d3db
Simplified tsconfig paths
bhalperin Jul 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"depConstraints": [
{
"sourceTag": "scope:app",
"onlyDependOnLibsWithTags": ["scope:lib-shared"]
"onlyDependOnLibsWithTags": ["scope:lib-shared", "scope:lib-config", "scope:lib-auth", "scope:lib-prisma", "scope:lib-users"]
}
]
}
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,19 @@ jobs:
- uses: nrwl/nx-set-shas@v4

- name: ===== Generate Prisma client =====
run: ./node_modules/.bin/prisma generate --schema=./apps/api/prisma/schema.prisma
run: ./node_modules/.bin/prisma generate --schema=./libs/prisma/src/lib/schema.prisma

- name: ===== Compile generated Prisma client =====
run: npx tsc -p libs/prisma/tsconfig.generated.json

- name: ===== List generate Prisma client files =====
run: ls -la libs/prisma/generated/prisma/client

# Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud
# - run: yarn nx-cloud record -- echo Hello World
# Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected
- name: ===== Lint and build =====
run: yarn run affected
run: yarn run affected --verbose

- name: ===== Run ui e2e tests =====
run: yarn run e2e:ui
run: yarn run e2e:ui --verbose
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Thumbs.db
# Production .env files
/apps/api/.env.prod
/apps/api/generated
/libs/prisma/generated

# .env copied to root before deploying the BE
.env
Expand Down
28 changes: 0 additions & 28 deletions apps/api/src/config/config.ts

This file was deleted.

9 changes: 3 additions & 6 deletions apps/api/src/modules/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { AuthService, GoogleAuthGuard, JwtAuthGuard, LocalAuthGuard } from '@gh/auth';
import { globalConfig } from '@gh/config';
import { User as PrismaUser } from '@gh/prisma';
import { AuthKeys } from '@gh/shared/models';
import { loggedMethod } from '@gh/shared/utils';
import { Body, Controller, Get, HttpCode, HttpStatus, Inject, Post, Req, Res, UnauthorizedException, UseGuards } from '@nestjs/common';
import { ConfigType } from '@nestjs/config';
import { ApiBody } from '@nestjs/swagger';
import { globalConfig } from 'config/config';
import { Request, Response } from 'express';
import { User as PrismaUser } from '../../../generated/prisma/client';
import { AuthService } from './auth.service';
import { LoginDto } from './dtos';
import { GoogleAuthGuard } from './google-auth.guard';
import { JwtAuthGuard } from './jwt-auth.guard';
import { LocalAuthGuard } from './local-auth.guard';

@Controller('auth')
export class AuthController {
Expand Down
12 changes: 4 additions & 8 deletions apps/api/src/modules/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import { AuthService, GoogleStrategy, JwtStrategy, LocalStrategy } from '@gh/auth';
import { PrismaService } from '@gh/prisma';
import { UsersService } from '@gh/users';
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { UsersModule } from '../users/users.module';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { GoogleStrategy } from './google.strategy';
import { JwtStrategy } from './jwt.strategy';
import { LocalStrategy } from './local.strategy';

@Module({
imports: [
UsersModule,
PassportModule,
JwtModule,
],
providers: [AuthService, LocalStrategy, JwtStrategy, GoogleStrategy],
exports: [AuthService],
providers: [AuthService, LocalStrategy, JwtStrategy, GoogleStrategy, PrismaService, UsersService],
controllers: [AuthController],
})
export class AuthModule {}
2 changes: 1 addition & 1 deletion apps/api/src/modules/github/github.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JwtAuthGuard } from '@gh/auth';
import { Controller, Get, Param, Query, UseGuards } from '@nestjs/common';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
import { GithubService } from './github.service';

@Controller('github')
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/modules/github/github.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { globalConfig } from '@gh/config';
import { HttpModule } from '@nestjs/axios';
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { globalConfig } from 'config/config';
import { AuthModule } from '../auth/auth.module';
import { GithubController } from './github.controller';
import { GithubService } from './github.service';
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/modules/users/users.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { JwtAuthGuard } from '@gh/auth';
import { UsersService } from '@gh/users';
import { Body, Controller, Delete, Get, Param, ParseIntPipe, Patch, Post, UseGuards } from '@nestjs/common';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
import { CreateUserDto, UpdateUserDto } from './dtos';
import { UsersService } from './users.service';

@Controller('auth-users')
export class UsersController {
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/modules/users/users.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PrismaService } from '@gh/prisma';
import { UsersService } from '@gh/users';
import { Module } from '@nestjs/common';
import { PrismaService } from 'api-prisma/prisma.service';
import { UsersController } from './users.controller';
import { UsersService } from './users.service';

@Module({
providers: [UsersService, PrismaService],
Expand Down
6 changes: 0 additions & 6 deletions apps/api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,5 @@
"noFallthroughCasesInSwitch": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"paths": {
"@gh/shared/*": ["libs/shared/src/lib/*"],
"config/*": [ "apps/api/src/config/*" ],
"api-prisma/*": [ "apps/api/src/prisma/*" ],
"utils/*": [ "apps/api/src/utils/*" ]
},
}
}
7 changes: 6 additions & 1 deletion apps/ui-e2e/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
{
"path": "./tsconfig.editor.json"
}
]
],
"compilerOptions": {
"paths": {
"@gh/shared/*": ["libs/shared/src/lib/*"]
}
}
}
11 changes: 11 additions & 0 deletions copy-files-prisma-generated.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"copyFiles": [
{
"from": "./libs/prisma/generated/**/*.*",
"to": "./dist/libs/prisma/generated"
}
],
"copyFilesSettings": {
"whenFileExists": "overwrite"
}
}
8 changes: 7 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ export default [
depConstraints: [
{
sourceTag: 'scope:app',
onlyDependOnLibsWithTags: ['scope:lib-shared'],
onlyDependOnLibsWithTags: [
'scope:lib-shared',
'scope:lib-config',
'scope:lib-auth',
'scope:lib-prisma',
'scope:lib-users',
],
},
],
},
Expand Down
7 changes: 7 additions & 0 deletions libs/auth/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# auth

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test auth` to execute the unit tests via [Jest](https://jestjs.io).
40 changes: 40 additions & 0 deletions libs/auth/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import baseConfig from '../../eslint.config.mjs';

export default [
...baseConfig,
{
ignores: ['!**/*', '**/generated/*'],
},
{
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
rules: {},
},
{
files: ['**/*.ts', '**/*.tsx'],
rules: {
'@nx/enforce-module-boundaries': [
'error',
{
enforceBuildableLibDependency: true,
allow: [],

depConstraints: [
{
sourceTag: 'scope:lib-auth',
onlyDependOnLibsWithTags: [
'scope:lib-config',
'scope:lib-prisma',
'scope:lib-shared',
'scope:lib-users',
]
},
],
},
],
},
},
{
files: ['**/*.js', '**/*.jsx'],
rules: {},
},
];
10 changes: 10 additions & 0 deletions libs/auth/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
displayName: 'auth',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/libs/auth',
};
15 changes: 15 additions & 0 deletions libs/auth/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@gh/auth",
"version": "0.0.1",
"dependencies": {
"bcrypt": "^6.0.0",
"rxjs": "^7.8.2",
"tslib": "^2.8.1"
},
"devDependencies": {
"@types/bcrypt": "^6.0.0"
},
"type": "commonjs",
"main": "./src/index.js",
"typings": "./src/index.d.ts"
}
30 changes: 30 additions & 0 deletions libs/auth/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "auth",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/auth/src",
"projectType": "library",
"tags": ["scope:lib-auth"],
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/auth",
"main": "libs/auth/src/index.ts",
"tsConfig": "libs/auth/tsconfig.lib.json",
"assets": ["libs/auth/*.md"]
}
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"]
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/auth/jest.config.ts"
}
}
}
}
1 change: 1 addition & 0 deletions libs/auth/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib';
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { globalConfig } from '@gh/config';
import { User as PrismaUser } from '@gh/prisma';
import { AuthProfile } from '@gh/shared/models';
import { UsersService } from '@gh/users';
import { Inject, Injectable, UnauthorizedException } from '@nestjs/common';
import { ConfigType } from '@nestjs/config';
import { JwtService } from '@nestjs/jwt';
import axios from 'axios';
import bcrypt from 'bcrypt';
import { globalConfig } from 'config/config';
import { User as PrismaUser } from '../../../generated/prisma/client';
import { UsersService } from '../users/users.service';

@Injectable()
export class AuthService {
Expand Down Expand Up @@ -90,6 +90,7 @@ export class AuthService {
return axios.get(`https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=${token}`);
} catch (error) {
console.error('Failed to revoke the token:', error);
return null;
}
}

Expand All @@ -101,6 +102,8 @@ export class AuthService {
if (!expiresIn || expiresIn <= 0) {
return true;
}

return false;
} catch {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ExecutionContext, Injectable, UnauthorizedException } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { AuthService } from './auth.service';

@Injectable()
export class GoogleAuthGuard extends AuthGuard('google') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { globalConfig } from '@gh/config';
import { Inject, Injectable } from '@nestjs/common';
import { ConfigType } from '@nestjs/config';
import { PassportStrategy } from '@nestjs/passport';
import { globalConfig } from 'config/config';
import { Strategy, VerifyCallback } from 'passport-google-oauth20';
import { AuthService } from './auth.service';

Expand All @@ -21,7 +21,7 @@ export class GoogleStrategy extends PassportStrategy(Strategy) {
}

// make sure to add this or else you won't get the refresh token
authorizationParams(): { [key: string]: string } {
override authorizationParams(): { [key: string]: string } {
return {
access_type: 'offline',
prompt: 'consent',
Expand Down
7 changes: 7 additions & 0 deletions libs/auth/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from './auth.service'
export * from './google-auth.guard';
export * from './google.strategy';
export * from './jwt-auth.guard';
export * from './jwt.strategy'
export * from './local-auth.guard';
export * from './local.strategy'
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AuthGuard } from '@nestjs/passport';

@Injectable()
export class JwtAuthGuard extends AuthGuard('jwt') {
canActivate(context: ExecutionContext) {
override canActivate(context: ExecutionContext) {
const request = context.switchToHttp().getRequest();

console.log('*** JwtAuthGuard / canActivate, endpoint called\n-----------------------------\nmethod:\t\t', request.method, '\nurl:\t\t', request.url, '\nauth header:\t', request.headers['authorization'], '\nbody:\t\t', request.body);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { globalConfig } from '@gh/config';
import { Inject, Injectable } from '@nestjs/common';
import { ConfigType } from '@nestjs/config';
import { PassportStrategy } from '@nestjs/passport';
import { globalConfig } from 'config/config';
import { ExtractJwt, Strategy } from 'passport-jwt';

@Injectable()
Expand Down
Loading
Loading