Skip to content

Commit

Permalink
feat(auth): Add auth module and add local, jwt, facebook authorizatio…
Browse files Browse the repository at this point in the history
…n with passport
  • Loading branch information
EndyKaufman committed Aug 4, 2018
1 parent 7c42401 commit ff66ae3
Show file tree
Hide file tree
Showing 70 changed files with 1,659 additions and 477 deletions.
20 changes: 19 additions & 1 deletion .nestcli.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
{
"language": "ts",
"collection": "@nestjs/schematics"
"collection": "@nestjs/schematics",
"projects": {
"demo": {
"root": "src/apps/demo/",
"sourceRoot": "src/apps/demo",
"projectType": "application"
},
"@rucken/core-nestjs": {
"root": "src/libs/core/",
"sourceRoot": "src/libs/core",
"projectType": "library"
},
"@rucken/auth-nestjs": {
"root": "src/libs/auth/",
"sourceRoot": "src/libs/auth",
"projectType": "library"
}
},
"defaultProject": "demo"
}
7 changes: 6 additions & 1 deletion _env
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ DEBUG=true
DEMO=false
NODE_MODULES_CACHE=false
NPM_CONFIG_PRODUCTION=false
DOMAIN=localhost
PORT=5000
SECRET_KEY=secret_key
EXTERNAL_PORT=5000
JWT_SECRET_KEY=secret_key
JWT_EXPIRATION_DELTA=7 days
JWT_AUTH_HEADER_PREFIX=JWT
FACEBOOK_CLIENT_ID=
FACEBOOK_CLIENT_SECRET=
FACEBOOK_OAUTH_REDIRECT_URI=http://localhost:5000/
DATABASE_URL=sqlite://database/sqlitedb.db
#DATABASE_URL=postgres://USER:PASSWORD@HOST:1105/NAME
#DATABASE_URL=sqlite://db.sqlite3
Expand Down
35 changes: 14 additions & 21 deletions ormconfig.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
const ConnectionString = require('connection-string').ConnectionString;
const config = require('dotenv').config;
const path = require('path');

const fs = require('fs');
const nestCliConfig = JSON.parse(fs.readFileSync('.nestcli.json'));
config();

const connectionString = new ConnectionString(process.env.DATABASE_URL);
const libs = Object.keys(nestCliConfig.projects).filter(key => nestCliConfig.projects[key].projectType === 'library').map(key => nestCliConfig.projects[key]);
const apps = Object.keys(nestCliConfig.projects).filter(key => nestCliConfig.projects[key].projectType === 'application').map(key => nestCliConfig.projects[key]);
const defaultProject = nestCliConfig.defaultProject;
const defaultApp = nestCliConfig.projects[defaultProject];

if (connectionString.protocol === 'sqlite') {
module.exports = {
type: 'sqlite',
database: './' + connectionString.hosts[0].name + (connectionString.path.length ? '/' + connectionString.path[0] : ''),
entities: [
'src/**/entities/**/*.entity.ts',
],
migrations: [
'src/**/migrations/**/*.ts'
],
subscribers: [
'src/**/subscribers/**/*.ts'
],
entities: libs.map(lib => `${lib.sourceRoot}/**/entities/**/*.entity.ts`),
migrations: libs.map(lib => `${lib.sourceRoot}/**/migrations/**/*.ts`),
subscribers: libs.map(lib => `${lib.sourceRoot}/**/subscribers/**/*.ts`),
logging: 'all',
synchronize: false,
cli: {
migrationsDir: 'src/apps/demo/migrations'
migrationsDir: `${defaultApp.sourceRoot}/migrations`
}
}
} else {
Expand All @@ -33,19 +32,13 @@ if (connectionString.protocol === 'sqlite') {
username: connectionString.user,
password: connectionString.password,
database: connectionString.segments[0],
entities: [
'src/**/entities/**/*.entity.ts',
],
migrations: [
'src/**/migrations/**/*.ts'
],
subscribers: [
'src/**/subscribers/**/*.ts'
],
entities: libs.map(lib => `${lib.sourceRoot}/**/entities/**/*.entity.ts`),
migrations: libs.map(lib => `${lib.sourceRoot}/**/migrations/**/*.ts`),
subscribers: libs.map(lib => `${lib.sourceRoot}/**/subscribers/**/*.ts`),
logging: 'all',
synchronize: false,
cli: {
migrationsDir: 'src/apps/demo/migrations'
migrationsDir: `${defaultApp.sourceRoot}/migrations`
}
}
}
106 changes: 95 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,26 @@
"test:cov": "jest --coverage",
"test:e2e": "jest --config ./test/jest-e2e.json",
"webpack": "webpack --config webpack.config.js",
"migrate:create": "ts-node ./node_modules/typeorm/cli.js migration:create",
"migrate:generate": "ts-node ./node_modules/typeorm/cli.js migration:generate",
"migrate": "ts-node ./node_modules/typeorm/cli.js migration:run",
"migrate:create": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js migration:create",
"migrate:generate": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js migration:generate",
"migrate": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js migration:run",
"docs": "./node_modules/.bin/typedoc --ignoreCompilerErrors --excludeExternals --out www/docs src",
"md-to-html": "showdown makehtml -i README.md -o www/index.html",
"frontend": "npm-run-all md-to-html",
"build": "npm-run-all clean prepare:core docs migrate prestart:prod frontend",
"build": "npm-run-all clean prepare docs migrate prestart:prod frontend",
"heroku-postbuild": "npm run build",
"prepare:core": "rucken make-ts-list ./src/libs/core"
"prepare:core": "rucken make-ts-list ./src/libs/core",
"prepare:auth": "rucken make-ts-list ./src/libs/auth",
"prepare": "npm-run-all prepare:core prepare:auth"
},
"dependencies": {
"@nestjs/common": "^5.1.0",
"@nestjs/core": "^5.1.0",
"@nestjs/passport": "^1.1.0",
"@nestjs/swagger": "^2.2.0",
"@nestjs/typeorm": "^5.1.0",
"@types/passport-facebook-token": "^0.4.33",
"@types/passport-local": "^1.0.33",
"class-transformer": "^0.1.9",
"class-validator": "^0.9.1",
"connection-string": "^1.0.1",
Expand All @@ -74,8 +78,10 @@
"jsonwebtoken": "^8.3.0",
"node-django-hashers": "^1.1.1",
"passport": "^0.4.0",
"passport-facebook-token": "^3.3.0",
"passport-http-bearer": "^1.0.1",
"passport-jwt": "^4.0.0",
"passport-local": "^1.0.0",
"reflect-metadata": "^0.1.12",
"rxjs": "^6.2.2",
"sqlite3": "^4.0.2",
Expand Down
9 changes: 6 additions & 3 deletions src/apps/demo/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Module, DynamicModule, Provider } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { CoreModule } from '../../libs/core/core.module';
import { CoreModule } from '@rucken/core-nestjs';
import { AuthModule } from '@rucken/auth-nestjs';

@Module({
imports: [
TypeOrmModule.forRoot(),
CoreModule
CoreModule,
AuthModule
]
})
export class AppModule {
Expand All @@ -14,7 +16,8 @@ export class AppModule {
module: AppModule,
imports: [
TypeOrmModule.forRoot(),
CoreModule.forRoot(options)
CoreModule.forRoot(options),
AuthModule.forRoot(options)
]
};
}
Expand Down
Loading

0 comments on commit ff66ae3

Please sign in to comment.